Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bazel.info.* commands #291

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
"onLanguage:starlark",
"onView:bazelWorkspace",
"onCommand:bazel.refreshBazelBuildTargets",
"onCommand:bazel.getTargetOutput"
"onCommand:bazel.getTargetOutput",
"onCommand:bazel.info.bazel-bin",
"onCommand:bazel.info.bazel-genfiles",
"onCommand:bazel.info.bazel-testlogs",
"onCommand:bazel.info.execution_root",
"onCommand:bazel.info.output_base",
"onCommand:bazel.info.output_path"
],
"main": "./out/src/extension/extension",
"contributes": {
Expand Down Expand Up @@ -88,6 +94,36 @@
"category": "Bazel",
"command": "bazel.getTargetOutput",
"title": "Get output path for the given target"
},
{
"category": "Bazel",
"command": "bazel.info.bazel-bin",
"title": "Get bazel-bin value"
},
{
"category": "Bazel",
"command": "bazel.info.bazel-genfiles",
"title": "Get bazel-genfiles value"
},
{
"category": "Bazel",
"command": "bazel.info.bazel-testlogs",
"title": "Get bazel-testlogs value"
},
{
"category": "Bazel",
"command": "bazel.info.execution_root",
"title": "Get Bazel execution_root value"
},
{
"category": "Bazel",
"command": "bazel.info.output_base",
"title": "Get Bazel output_base value"
},
{
"category": "Bazel",
"command": "bazel.info.output_path",
"title": "Get Bazel output_path value"
}
],
"configuration": {
Expand Down
32 changes: 32 additions & 0 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ export function activate(context: vscode.ExtensionContext) {
"bazel.getTargetOutput",
bazelGetTargetOutput,
),
...[
"bazel-bin",
"bazel-genfiles",
"bazel-testlogs",
"execution_root",
"output_base",
"output_path",
].map((key) =>
vscode.commands.registerCommand(`bazel.info.${key}`, () =>
bazelInfo(key),
),
),
// CodeLens provider for BUILD files
vscode.languages.registerCodeLensProvider(
[{ pattern: "**/BUILD" }, { pattern: "**/BUILD.bazel" }],
Expand Down Expand Up @@ -466,6 +478,26 @@ async function bazelGetTargetOutput(
}
}

/**
* Get the output of `bazel info` for the given key.
*
* If there are multiple outputs, a quick-pick window will be opened asking the
* user to choose one.
*/
async function bazelInfo(key: string): Promise<string> {
const workspaceInfo = await BazelWorkspaceInfo.fromWorkspaceFolders();
if (!workspaceInfo) {
vscode.window.showInformationMessage(
"Please open a Bazel workspace folder to use this command.",
);
return;
}
return new BazelInfo(
getDefaultBazelExecutablePath(),
workspaceInfo.bazelWorkspacePath,
).run(key);
}

function onTaskStart(event: vscode.TaskStartEvent) {
const bazelTaskInfo = getBazelTaskInfo(event.execution.task);
if (bazelTaskInfo) {
Expand Down