Skip to content

Add a when clause context key for detecting if an extension is installed+enabled - #326814

Merged
Connor Peet (connor4312) merged 7 commits into
microsoft:mainfrom
bwateratmsft:bwateratmsft-extension-installed-context-key
Jul 23, 2026
Merged

Connor Peet (connor4312) merged 7 commits into
microsoft:mainfrom
bwateratmsft:bwateratmsft-extension-installed-context-key

Conversation

@bwateratmsft

@bwateratmsft Brandon Waterloo [MSFT] (bwateratmsft) commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #326815.

This PR adds a when clause context key for detecting if an extension is installed+enabled. This is useful in cases where you want to hide something (e.g. a duplicate view or command, etc.), but do not control the other extension, or do not want to rely on it being activated first.

Submitting as a draft for now, due to ongoing feed issues I cannot actually do npm install locally.

Mirror the set of installed and enabled extensions into per-extension
context keys (extensionEnabled:<lowercased id>) so authors can gate UI
via when clauses without activating the extension.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cb195182-bee3-4aaf-b33b-ceb8e36e3f18
Copilot AI review requested due to automatic review settings July 21, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Introduces per-extension context keys for gating UI based on extension presence, currently using registered/enabled extension state.

Changes:

  • Adds extensionEnabled:<id> context keys.
  • Updates keys when extensions change.
  • Adds lifecycle registration and unit tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
extensionEnablementContext.ts Implements extension context keys.
extensions.contribution.ts Registers the contribution.
extensionEnablementContext.test.ts Tests initialization, updates, and ID normalization.

Comment thread src/vs/workbench/contrib/extensions/browser/extensionEnablementContext.ts Outdated
Comment thread src/vs/workbench/contrib/extensions/browser/extensionEnablementContext.ts Outdated
@bwateratmsft Brandon Waterloo [MSFT] (bwateratmsft) changed the title Add a when clause context key for detecting if an extension is installed Add a when clause context key for detecting if an extension is installed+enabled Jul 21, 2026
Address CCR feedback: seed on onDidRegisterExtensions (extensions list is empty until initial registration, which the Restored phase does not guarantee) and reconcile against the authoritative extensionService.extensions set instead of trusting change deltas (which can report added extensions that validation later rejects due to dependency loops). Adds a regression test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: cb195182-bee3-4aaf-b33b-ceb8e36e3f18
@bwateratmsft
Brandon Waterloo [MSFT] (bwateratmsft) marked this pull request as ready for review July 23, 2026 16:26
@bwateratmsft

Brandon Waterloo [MSFT] (bwateratmsft) commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Verified this works end-to-end. Updating the branch to see if that fixes the build breaks, they look unrelated.

Using a dummy extension with a command gated on this extensionEnabled, I checked:

  1. Target extension disabled--command not visible
  2. Target extension enabled--command visible
  3. Target extension changes from enabled to disabled--command goes from visible=>not
  4. Target extension changes from disabled to enabled--command goes from not=>visible

@connor4312
Connor Peet (connor4312) merged commit 7e5ad0c into microsoft:main Jul 23, 2026
46 of 47 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.131.0 milestone Jul 23, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a when clause context key that can detect if another extension is installed/enabled

7 participants