Skip to content

formatting: ask where to save default formatter - user or workspace (#71755)#317959

Open
RajeshKumar11 wants to merge 1 commit into
microsoft:mainfrom
RajeshKumar11:fix/default-formatter-scope-picker-71755
Open

formatting: ask where to save default formatter - user or workspace (#71755)#317959
RajeshKumar11 wants to merge 1 commit into
microsoft:mainfrom
RajeshKumar11:fix/default-formatter-scope-picker-71755

Conversation

@RajeshKumar11
Copy link
Copy Markdown
Contributor

Fixes #71755

Summary

When selecting a default formatter via the "Format Document With..." command, VS Code previously always wrote editor.defaultFormatter to 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:

  • User Settings — applies to all VS Code instances (previous behavior, still the default when no workspace is open)
  • Workspace Settings — writes to .vscode/settings.json in the current workspace

If 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):

  1. Pick formatter → e.g. "Prettier"
  2. Pick target → "User Settings" or "Workspace Settings"
  3. Setting written to chosen target

After (no workspace): Same as before — skips step 2, writes to User Settings.

Files Changed

  • src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts
    • Added ConfigurationTarget and IWorkspaceContextService/WorkbenchState imports
    • Injected IWorkspaceContextService into DefaultFormatter
    • Extended _pickAndPersistDefaultFormatter with a second target-selection step

Copilot AI review requested due to automatic review settings May 22, 2026 08:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default formatter selection should write to project specific settings rather than global.

3 participants