diff --git a/CHANGELOG.md b/CHANGELOG.md index 5acc840ad..82106dd93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Improvements: - Fix "Test output isn't visible when failed" and also mark skipped tests as so. [#4116](https://github.com/microsoft/vscode-cmake-tools/issues/4116) - Ensure that stopping tests actually forces the tests to stop running. [#2095](https://github.com/microsoft/vscode-cmake-tools/issues/2095) - Retire the Show Options Moved Notification [#4039](https://github.com/microsoft/vscode-cmake-tools/issues/4039) +- Improve the pinned commands experience by defaulting settings and using VS Code state rather than modifying user settings. [#3977](https://github.com/microsoft/vscode-cmake-tools/issues/3977) Bug Fixes: diff --git a/package.json b/package.json index 78ba483ee..20bc2c09e 100644 --- a/package.json +++ b/package.json @@ -3578,7 +3578,10 @@ "type": "string" }, "description": "%cmake-tools.configuration.cmake.pinnedCommands.description%", - "default": [], + "default": [ + "workbench.action.tasks.configureTaskRunner", + "workbench.action.tasks.runTask" + ], "scope": "resource" }, "cmake.enableAutomaticKitScan": { diff --git a/package.nls.json b/package.nls.json index 38bb7c7d7..74ba6956c 100644 --- a/package.nls.json +++ b/package.nls.json @@ -271,7 +271,7 @@ }, "cmake-tools.configuration.cmake.launchBehavior.description": "Controls what happens with the launch terminal when you launch a target.", "cmake-tools.configuration.cmake.automaticReconfigure.description": "Automatically configure CMake project directories when the kit or the configuration preset is changed.", - "cmake-tools.configuration.cmake.pinnedCommands.description":"List of CMake commands to pin.", + "cmake-tools.configuration.cmake.pinnedCommands.description":"List of CMake commands to always pin by default.", "cmake-tools.configuration.cmake.enableAutomaticKitScan.description": "Enable automatic scanning for kits when a kit isn't selected. This will only take affect when CMake Presets aren't being used.", "cmake-tools.debugger.pipeName.description": "Name of the pipe (on Windows) or domain socket (on Unix) to use for debugger communication.", "cmake-tools.debugger.clean.description": "Clean prior to configuring.", diff --git a/src/ui/pinnedCommands.ts b/src/ui/pinnedCommands.ts index 26b544ebb..8e5231cd3 100644 --- a/src/ui/pinnedCommands.ts +++ b/src/ui/pinnedCommands.ts @@ -8,7 +8,6 @@ nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFo const localize: nls.LocalizeFunc = nls.loadMessageBundle(); const log = logging.createLogger('pinnedCommands'); const defaultTaskCommands: string[] = ["workbench.action.tasks.configureTaskRunner", "workbench.action.tasks.runTask"]; -const mementoKey = "pinDefaultTasks"; interface PinnedCommandsQuickPickItem extends vscode.QuickPickItem { command: string; @@ -97,7 +96,6 @@ class PinnedCommandsTreeDataProvider implements vscode.TreeDataProvider this.doConfigureSettingsChange()); this.config = vscode.workspace.getConfiguration(); this.extensionContext = extensionContext; - this.pinDefaultTasks = this.extensionContext.globalState.get(mementoKey) === undefined; // the user has not unpinned any of the tasks commands yet. onExtensionActiveCommandsChanged(this.doConfigureSettingsChange, this); } @@ -118,29 +115,29 @@ class PinnedCommandsTreeDataProvider implements vscode.TreeDataProvider(PinnedCommands.getPinnableCommands()); - for (const commandName of settingsPinnedCommands) { - const label = localization[`cmake-tools.command.${commandName}.title`]; + const activeCommands = new Set(PinnedCommands.getPinnableCommands()); + + const tryPushCommands = (commands: string[]) => { + commands.forEach((x) => { + const label = localization[`cmake-tools.command.${x}.title`]; if (this.findNode(label) === -1) { - // only show commands that are contained in the active commands for the extension. - this.pinnedCommands.push(new PinnedCommandNode(label, commandName, activeCommands.has(commandName))); + this.pinnedCommands.push(new PinnedCommandNode(label, x, activeCommands.has(x))); } - } + }); + }; + + // Pin the commands that are requested from the users settings. + if (this.config.has(this.pinnedCommandsKey)) { + const settingsPinnedCommands = this.config.get(this.pinnedCommandsKey) as string[]; + tryPushCommands(settingsPinnedCommands); } - if (this.pinDefaultTasks) { - if (this.pinnedCommands.filter(x => defaultTaskCommands.includes(x.commandName)).length !== defaultTaskCommands.length) { - defaultTaskCommands.forEach((x) => { - const label = localization[`cmake-tools.command.${x}.title`]; - if (this.findNode(label) === -1) { - this.pinnedCommands.push(new PinnedCommandNode(label, x, true)); - } - }); - await this.updateSettings(); - } + // Pin commands that were pinned in the last session. + const lastSessionPinnedCommands = this.extensionContext.workspaceState.get(this.pinnedCommandsKey) as string[]; + if (lastSessionPinnedCommands) { + tryPushCommands(lastSessionPinnedCommands); } + this.isInitialized = true; } @@ -174,10 +171,6 @@ class PinnedCommandsTreeDataProvider implements vscode.TreeDataProvider x.commandName); - await this.config.update(this.pinnedCommandsKey, newValue, true); // update global + const pinnedCommands: string[] = this.pinnedCommands.map(x => x.commandName); + await this.extensionContext.workspaceState.update(this.pinnedCommandsKey, pinnedCommands); } }