microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.25k stars 29.3k forks source link

Unable to pass `target: Workspace` to `workbench.action.openSettings2` command #226071

Open DanTup opened 2 months ago

DanTup commented 2 months ago

I'm like to pop open the settings editor for a specific setting, but for the current workspace. Eg, this view:

image

I'm using the workbench.action.openSettings2 command (to force the UI regardless of user settings) and passing a query. I'm also passing a target (which I found in ISettingsEditorOptions alongside query), however it seems to be ignored and just opens at the user settings:

await vs.commands.executeCommand("workbench.action.openSettings2", {
    query: settingName,
    target: vs.ConfigurationTarget.Workspace,
});

image

I also tried passing 5 instead of vs.ConfigurationTarget.Workspace, because there's another ConfigurationTarget enum inside VS Code defined as:

export const enum ConfigurationTarget {
    APPLICATION = 1,
    USER,
    USER_LOCAL,
    USER_REMOTE,
    WORKSPACE, // 5
    WORKSPACE_FOLDER,
    DEFAULT,
    MEMORY
}

However, nothing works. I saw there as a new vscode://settings/xxx handler in the latest VS Code, but it doesn't seem to have any option for workspace settings.

Is this a bug? Is there a way to do the equiv of "Open Workspace Settings" and force the UI, and provide a query?

ArturoDent commented 2 months ago

This appears to work:

await vs.commands.executeCommand("workbench.action.openWorkspaceSettings", {
  query: 'window.zoomLevel'
  // target: vs.ConfigurationTarget.Workspace,
});
DanTup commented 2 months ago

@ArturoDent I think that only works if you haven't changed your settings to default to the JSON editor though, otherwise it'll open the JSON editor. I want to force the UI regardless of the user preference because otherwise if the user hasn't already defined the setting, they will just end up at a blank json file.