Skip to content

fix: make hatch.envInterpreter enablement a valid when-clause#195

Merged
flying-sheep merged 1 commit into
pypa:mainfrom
d-biehl:fix/command-enablement-when-clause
Jun 1, 2026
Merged

fix: make hatch.envInterpreter enablement a valid when-clause#195
flying-sheep merged 1 commit into
pypa:mainfrom
d-biehl:fix/command-enablement-when-clause

Conversation

@d-biehl

@d-biehl d-biehl commented May 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #194.

Problem

hatch.envInterpreter was contributed with "enablement": false — a boolean. Per the contribution-points reference, a command's enablement is a when clause, i.e. a string context-key expression (the commandType schema in menusExtensionPoint.ts declares it as type: 'string').

VS Code passes the value straight to ContextKeyExpr.deserialize, whose scanner calls charCodeAt on it. A boolean has no charCodeAt, so it throws a TypeError that aborts the commands extension-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 logs Menu 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 enablement a valid when-clause expression by using the string "false" instead of the boolean:

"commands": [
  {
    "command": "hatch.envInterpreter",
    "title": "Hatch: Get an environment’s interpreter path",
    "enablement": "false"
  }
]

hatch.envInterpreter is only invoked programmatically via executeCommand (see src/extension.ts), so it never needs a UI affordance. enablement: "false":

  • fixes the crash (a string deserializes fine),
  • hides the command from the Command Palette (the palette filters out disabled commands), and
  • disables it across all menus and keybindings — broader than a commandPalette when clause, which only covers the palette.

executeCommand bypasses enablement, so the command stays fully usable programmatically. biome check passes.

Copilot AI review requested due to automatic review settings May 31, 2026 00:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 enablement property from the command declaration.
  • Adds a menus.commandPalette entry to hide the command from the command palette.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@flying-sheep flying-sheep left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use enablement instead: https://code.visualstudio.com/api/references/contribution-points#contributes.menus

Note that when clauses apply to menus and enablement clauses to commands. The enablement applies 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
@d-biehl d-biehl force-pushed the fix/command-enablement-when-clause branch from 8446089 to bf9f6f7 Compare May 31, 2026 22:36
@d-biehl

d-biehl commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Switched to "enablement": "false" (string) as suggested. 👍

@flying-sheep flying-sheep merged commit 68287b0 into pypa:main Jun 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] enablement: false` (boolean) on a command breaks command registration for all extensions loaded afterwards

3 participants