Fix #244138: Match extension Disable/Enable dropdown primary to current scope#309999
Open
Hude06 wants to merge 2 commits intomicrosoft:mainfrom
Open
Fix #244138: Match extension Disable/Enable dropdown primary to current scope#309999Hude06 wants to merge 2 commits intomicrosoft:mainfrom
Hude06 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
… to current scope When an extension is in EnablementState.EnabledWorkspace (disabled globally but enabled in this workspace), the extensions view shows a primary button labelled "Disable" whose dropdown lists both "Disable" and "Disable (Workspace)". Clicking the primary discards the workspace customization. The mirror bug exists for DisabledWorkspace. Add a protected selectPrimaryAction hook on ButtonWithDropDownExtensionAction (defaults to actions[0]) and override it in EnableDropDownAction and DisableDropDownAction to prefer the workspace-scoped child when the extension's enablementState matches. The menu still contains both actions, so all four enablement states remain reachable — addressing the state-loop concern raised on microsoft#244419.
Author
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #244138.
The bug
When an extension is in
EnablementState.EnabledWorkspace(disabled globally but enabled for this workspace), the extensions view shows a primary button labelled "Disable" with a dropdown containing both "Disable" and "Disable (Workspace)". Clicking the primary wipes the workspace customization the user just set up. The mirror bug exists forDisabledWorkspace: the primary is "Enable" (global) when it should be "Enable (Workspace)".Desired behaviour
EnabledGloballyEnabledWorkspaceDisabledWorkspaceDisabledGloballyBold rows are the cases this PR fixes. Every state remains reachable from every other state via the dropdown, which was the concern raised on #244419 — see below.
Why the previous attempts were closed
Three prior PRs tried to fix this (#244419, #246500, #251531) and were all closed. The common failure mode was hiding the global action from the dropdown when in a workspace state, which created a state-transition loop: once the user selected a workspace-scoped action, they could never reach the global enable/disable again (sandy081's comment on #244419).
This PR does not hide any actions. It only swaps which action is primary.
setEnablement(ext, EnabledGlobally)andsetEnablement(ext, DisabledGlobally)already clear workspace overrides inextensionEnablementService.ts, so the global actions in the dropdown continue to function as the loop-breaker.Implementation
protected selectPrimaryAction(actions)hook toButtonWithDropDownExtensionAction. Default returnsactions[0](no behaviour change for any other dropdown subclass).ButtonWithDropDownExtensionAction.update(), reorder so the chosen primary appears first in the menu.selectPrimaryActioninEnableDropDownActionto preferEnableForWorkspaceActionwhenenablementState === DisabledWorkspace.selectPrimaryActioninDisableDropDownActionto preferDisableForWorkspaceActionwhenenablementState === EnabledWorkspace.The override only triggers when the workspace-scoped child is actually
enabled, so it cannot accidentally promote a non-actionable action.Tests
Four new tests in
src/vs/workbench/contrib/extensions/test/electron-browser/extensionsActions.test.ts:EnableDropDownAction primary is workspace action when extension is disabled in workspace— asserts label isEnable (Workspace).EnableDropDownAction primary is global action when extension is disabled globally— regression test, asserts label isEnable.DisableDropDownAction primary is workspace action when extension is enabled in workspace— asserts label isDisable (Workspace).DisableDropDownAction primary is global action when extension is enabled globally— regression test, asserts label isDisable.Verification
npm run compile-check-ts-nativepasses with no new errors.EnableDropDownAction/DisableDropDownActiontests still pass (the default hook returnsactions[0], matching prior behaviour for any state not explicitly handled).cc @sandy081