formatting: ask where to save default formatter - user or workspace (#71755)#317959
Open
RajeshKumar11 wants to merge 1 commit into
Open
formatting: ask where to save default formatter - user or workspace (#71755)#317959RajeshKumar11 wants to merge 1 commit into
RajeshKumar11 wants to merge 1 commit into
Conversation
Contributor
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 updates the default formatter selection flow to let users choose whether the chosen formatter is saved to User Settings or Workspace Settings when a workspace is open.
Changes:
- Adds workspace context awareness to detect when a workspace is open.
- Prompts the user for a settings target (User vs Workspace) before persisting the selected default formatter.
- Writes the setting using the selected
ConfigurationTarget.
Comment on lines
+221
to
+237
| // Ask whether to save in user settings or workspace settings (when a workspace is open) | ||
| let configTarget = ConfigurationTarget.USER; | ||
| const workbenchState = this._workspaceContextService.getWorkbenchState(); | ||
| if (workbenchState !== WorkbenchState.EMPTY) { | ||
| interface ITargetPick extends IQuickPickItem { target: ConfigurationTarget; } | ||
| const targetPick = await this._quickInputService.pick<ITargetPick>( | ||
| [ | ||
| { label: nls.localize('userSettings', "User Settings"), description: nls.localize('userSettingsDescription', "Apply to all VS Code instances"), target: ConfigurationTarget.USER }, | ||
| { label: nls.localize('workspaceSettings', "Workspace Settings"), description: nls.localize('workspaceSettingsDescription', "Apply only to the current workspace"), target: ConfigurationTarget.WORKSPACE }, | ||
| ], | ||
| { placeHolder: nls.localize('selectTarget', "Where do you want to save this setting?") } | ||
| ); | ||
| if (!targetPick) { | ||
| return undefined; | ||
| } | ||
| configTarget = targetPick.target; | ||
| } |
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 #71755
Summary
When selecting a default formatter via the "Format Document With..." command, VS Code previously always wrote
editor.defaultFormatterto User Settings, making it apply to all projects. This is the opposite of the feature's primary advertised use case (per-project formatters).This PR adds a second quick-pick step that asks where to save the setting when a workspace is open:
.vscode/settings.jsonin the current workspaceIf no workspace folder is open (empty/untitled window), the step is skipped and the setting writes to User Settings as before.
Behavior
Before: editor.defaultFormatter always written to global user settings.
After (workspace open):
After (no workspace): Same as before — skips step 2, writes to User Settings.
Files Changed
src/vs/workbench/contrib/format/browser/formatActionsMultiple.tsConfigurationTargetandIWorkspaceContextService/WorkbenchStateimportsIWorkspaceContextServiceintoDefaultFormatter_pickAndPersistDefaultFormatterwith a second target-selection step