fix: make hatch.envInterpreter enablement a valid when-clause#195
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR migrates the hatch.envInterpreter command's palette-hiding configuration from the deprecated enablement: false property to the recommended menus.commandPalette with when: "false" clause.
Changes:
- Removes the
enablementproperty from the command declaration. - Adds a
menus.commandPaletteentry to hide the command from the command palette.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
flying-sheep
left a comment
There was a problem hiding this comment.
Please use enablement instead: https://code.visualstudio.com/api/references/contribution-points#contributes.menus
Note that
whenclauses apply to menus andenablementclauses to commands. Theenablementapplies to all menus and even keybindings while the when only applies to a single menu.
That’s what we want.
The command was contributed with `"enablement": false` (a boolean), but `command.enablement` must be a string when-clause. VS Code feeds the value through `ContextKeyExpr.deserialize`, which calls `charCodeAt` on it and throws a TypeError. That exception aborts the commands extension-point handler mid-iteration, so every extension processed after Hatch loses its command registration (commands missing from the Command Palette, plus "command not defined in the 'commands' section" menu errors). Since `hatch.envInterpreter` is only invoked programmatically via `executeCommand`, drop `enablement` and hide it from the Command Palette with a `commandPalette` `when: "false"` menu entry instead. Fixes pypa#194
8446089 to
bf9f6f7
Compare
|
Switched to |
Fixes #194.
Problem
hatch.envInterpreterwas contributed with"enablement": false— a boolean. Per the contribution-points reference, a command'senablementis awhenclause, i.e. a string context-key expression (thecommandTypeschema inmenusExtensionPoint.tsdeclares it astype: 'string').VS Code passes the value straight to
ContextKeyExpr.deserialize, whose scanner callscharCodeAton it. A boolean has nocharCodeAt, so it throws aTypeErrorthat aborts thecommandsextension-point handler mid-iteration. Every extension whose commands are registered after Hatch then loses its command registration: those commands disappear from the Command Palette, and VS Code logsMenu item references a command ... which is not defined in the 'commands' section.for each of their menu items.The effect is order-dependent and platform-independent (reproduced on Linux and Windows, on VS Code stable and Insiders).
Fix
Make
enablementa validwhen-clause expression by using the string"false"instead of the boolean:hatch.envInterpreteris only invoked programmatically viaexecuteCommand(seesrc/extension.ts), so it never needs a UI affordance.enablement: "false":commandPalettewhenclause, which only covers the palette.executeCommandbypasses enablement, so the command stays fully usable programmatically.biome checkpasses.