Skip to content

Commit

Permalink
Add support to configure default ActiveProject (#3730)
Browse files Browse the repository at this point in the history
* Implemented defaultActiveProject configuration to select default project during initialization (#1078)

* Updated docu

* Removed unused comment

* Fixed lint issues

* Fixed review findings

* Improved description of new defaultActiveFolder configuration

* Updated changelog

---------

Co-authored-by: Garrett Campbell <[email protected]>
  • Loading branch information
sanore and gcampbell-msft authored Oct 10, 2024
1 parent 68c6dab commit 9327d3c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Features:

- Add support for Presets v9, which enables more macro expansion for the `include` field. [#3946](https://github.com/microsoft/vscode-cmake-tools/issues/3946)
- Add support to configure default folder in workspace setting. [#1078](https://github.com/microsoft/vscode-cmake-tools/issues/1078)

Improvements:

Expand Down
1 change: 1 addition & 0 deletions docs/cmake-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Options that support substitution, in the table below, allow variable references
|Setting |Description | Default value | Supports substitution |
|---------|---------|---------|-----|
| `cmake.autoSelectActiveFolder`| If 'false', your active folder only changes if you manually run the `CMake: Select Active Folder` command. | 'true' | no |
| `cmake.defaultActiveFolder`| The name of active folder, which be used as default (Only works when ´cmake.autoSelectActiveFolder´ is disabled). | "" | no |
| `cmake.buildArgs` | An array of additional arguments to pass to `cmake --build`. | `[]` (empty array-no additional arguments) | yes |
| `cmake.buildBeforeRun` | If `true`, build the launch/debug target before running the target. | `true` | no |
| `cmake.buildDirectory` | Specify the build directory (i.e. the root directory where `CMakeCache.txt` will be generated.) | `${workspaceFolder}/build` | yes |
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,12 @@
"description": "%cmake-tools.configuration.cmake.autoSelectActiveFolder.description%",
"scope": "window"
},
"cmake.defaultActiveFolder": {
"type": "string",
"default": "",
"description": "%cmake-tools.configuration.cmake.defaultActiveFolder.description%",
"scope": "window"
},
"cmake.cmakePath": {
"type": "string",
"default": "cmake",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"cmake-tools.configuration.cmake.outputLogEncoding.description": "Encoding of the output from external commands (eg.cmake -- build).",
"cmake-tools.configuration.cmake.enableTraceLogging.description": "Enable trace logging to file and console (very noisy).",
"cmake-tools.configuration.cmake.autoSelectActiveFolder.description": "Select active folder automatically.",
"cmake-tools.configuration.cmake.defaultActiveFolder.description": "Set the default active folder (only works when cmake.autoSelectActiveFolder is disable).",
"cmake-tools.configuration.cmake.touchbar.advanced.description": "Configures advanced settings for how the extension displays buttons on a MacBook Touch Bar.",
"cmake-tools.configuration.cmake.touchbar.visibility.description": "Configures how the extension displays the buttons on a MacBook Touch Bar.",
"cmake-tools.configuration.cmake.touchbar.visibility.default.description": "Show Touch Bar buttons on supported systems.",
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export interface OptionConfig {

export interface ExtensionConfigurationSettings {
autoSelectActiveFolder: boolean;
defaultActiveFolder: string | null;
cmakePath: string;
buildDirectory: string;
installPrefix: string | null;
Expand Down Expand Up @@ -314,6 +315,9 @@ export class ConfigurationReader implements vscode.Disposable {
get autoSelectActiveFolder(): boolean {
return this.configData.autoSelectActiveFolder;
}
get defaultActiveFolder(): string | null {
return this.configData.defaultActiveFolder;
}
buildDirectory(multiProject: boolean, workspaceFolder?: vscode.ConfigurationScope): string {
if (multiProject && this.isDefaultValue('buildDirectory', workspaceFolder)) {
return '${sourceDirectory}/build';
Expand Down Expand Up @@ -564,6 +568,7 @@ export class ConfigurationReader implements vscode.Disposable {

private readonly emitters: EmittersOf<ExtensionConfigurationSettings> = {
autoSelectActiveFolder: new vscode.EventEmitter<boolean>(),
defaultActiveFolder: new vscode.EventEmitter<string | null>(),
cmakePath: new vscode.EventEmitter<string>(),
buildDirectory: new vscode.EventEmitter<string>(),
installPrefix: new vscode.EventEmitter<string | null>(),
Expand Down
11 changes: 10 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,19 @@ export class ExtensionManager implements vscode.Disposable {
if (activeFolder) {
folder = vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(activeFolder));
}

let activeTextEditor = vscode.window.activeTextEditor;
const defaultActiveFolder = this.workspaceConfig.defaultActiveFolder;
if (defaultActiveFolder) {
// do not use the active text editor for updating active project
activeTextEditor = undefined;
folder = vscode.workspace.workspaceFolders!.find(candidate => candidate.uri.path.endsWith(defaultActiveFolder));
}

if (!folder) {
folder = vscode.workspace.workspaceFolders![0];
}
await this.updateActiveProject(folder, vscode.window.activeTextEditor);
await this.updateActiveProject(folder, activeTextEditor);
return this.getActiveProject();
}

Expand Down
1 change: 1 addition & 0 deletions test/unit-tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from '@test/util';
function createConfig(conf: Partial<ExtensionConfigurationSettings>): ConfigurationReader {
const ret = new ConfigurationReader({
autoSelectActiveFolder: false,
defaultActiveFolder: null,
cmakePath: '',
buildDirectory: '',
installPrefix: null,
Expand Down

0 comments on commit 9327d3c

Please sign in to comment.