Skip to content

Commit

Permalink
Introduce optional setting to specify a bazel workspace dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bytebat committed Jan 8, 2024
1 parent e8ea9b3 commit 3c26d6e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ clangd seems to have problems to resolve "isystem" added includes placed in the
### Fixed

- Use only selected workspace for test discovery

## [0.6.5] 2024-01-08

### Added

- Provide additional setting to specify bazel workspace file
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ Depending on the size of your C++ project, the test discovery process might take
* `vsc-bazel-tools.customCompileCommandsTarget`: Specifies a custom bazel target (label) to generate the compile commands.
* `vsc-bazel-tools.activateTesting`: Discover and publish tests via test explorer UI.
* `vsc-bazel-tools.testDiscoverLabel`: Bazel label for test discovery (e.g. `//my/package/...`).
* `vsc-bazel-tools.bazelWorkspaceDir`: The bazel workspace directory to work with. Optional setting in case of multiple valid `WORKSPACE` files.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vsc-bazel-tools",
"displayName": "VSC Bazel Tools",
"description": "IntelliSense support for C/C++ targets built with bazel.",
"version": "0.6.4",
"version": "0.6.5",
"publisher": "bjob",
"icon": "images/bazel_tools_icon.png",
"readme": "README.md",
Expand Down Expand Up @@ -60,6 +60,14 @@
],
"default": "//...",
"description": "This label will be used to search for tests. Defaults to workspace search (//...)"
},
"vsc-bazel-tools.bazelWorkspaceDir": {
"type": [
"string",
"null"
],
"default": null,
"description": "Full path to a bazel workspace directory (substitution of predefined vsc variables is currently not possible)."
}
}
}
Expand Down
26 changes: 16 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let bazelTestCtrl: vscode.TestController | undefined;
const bazelTools = "vsc-bazel-tools";
const activeTestingSettingName = "activateTesting";
const testDiscoverLabelSettingName = "testDiscoverLabel";
const workspaceDirSettingName = "bazelWorkspaceDir";
const activeTestingSettingDefault = true;
let testingActivated = false;

Expand All @@ -29,19 +30,24 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}

// take the first match as default and prompt for selection in case of multiple matches
let bazelWorkspaceDir = foundWorkspaceFiles[0];
if (foundWorkspaceFiles.length > 1) {
bazelWorkspaceDir = await vscode.window.showQuickPick(foundWorkspaceFiles, {
placeHolder: 'Choose bazel workspace...',
ignoreFocusOut: true,
});
}
bazelWorkspaceDir = path.dirname(bazelWorkspaceDir);

logger.info("Retrieving configuration.");
const config = vscode.workspace.getConfiguration(bazelTools);

// Use setting or take the first match as default and prompt for selection in case of multiple matches
let bazelWorkspaceDir = foundWorkspaceFiles[0];
const workSpaceDirFromConfig = config.get<string>(workspaceDirSettingName);
if (workSpaceDirFromConfig) {
bazelWorkspaceDir = vscode.Uri.file(workSpaceDirFromConfig).fsPath;
} else {
if (foundWorkspaceFiles.length > 1) {
bazelWorkspaceDir = await vscode.window.showQuickPick(foundWorkspaceFiles, {
placeHolder: 'Choose bazel workspace file ...',
ignoreFocusOut: true,
});
}
bazelWorkspaceDir = path.dirname(bazelWorkspaceDir);
}

compileCommandsGenerator = vscode.commands.registerCommand('vsc-bazel-tools.generateCompileCommands', async () => {
vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
Expand Down

0 comments on commit 3c26d6e

Please sign in to comment.