Skip to content

Commit

Permalink
Enable the "Restart LSP" command only if a LSP is configured
Browse files Browse the repository at this point in the history
This commit hides the "Restart LSP" command from the Command Palette if
the LSP is disabled. Otherwise, trying to use the "Restart LSP" command
without any LSP being configured leads to a user-visible error.

As part of this, I also renamed `vscodeBazelHaveBazelWorkspace` to
`bazel.haveWorkspace` such that the context variables all share a common
`bazel.*` prefix.
  • Loading branch information
vogelsgesang committed Feb 27, 2024
1 parent 995229b commit bfdafa1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
{
"category": "Bazel",
"command": "bazel.lsp.restart",
"title": "Restart language server"
"title": "Restart language server",
"when": "bazel.lsp.enabled"
}
],
"configuration": {
Expand Down Expand Up @@ -314,39 +315,39 @@
},
{
"command": "bazel.buildTarget",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.buildTargetWithDebugging",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.buildAll",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.buildAllRecursive",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.runTarget",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.testTarget",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.testAll",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.testAllRecursive",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
},
{
"command": "bazel.clean",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
}
],
"view/item/context": [
Expand Down Expand Up @@ -443,7 +444,7 @@
{
"id": "bazelWorkspace",
"name": "Bazel Build Targets",
"when": "vscodeBazelHaveBazelWorkspace"
"when": "bazel.haveWorkspace"
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export async function activate(context: vscode.ExtensionContext) {
),
);
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.commands.executeCommand("setContext", "bazel.lsp.enabled", lspEnabled);

context.subscriptions.push(
vscode.window.registerTreeDataProvider(
Expand Down
2 changes: 1 addition & 1 deletion src/workspace-tree/bazel_workspace_tree_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class BazelWorkspaceTreeProvider
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.commands.executeCommand(
"setContext",
"vscodeBazelHaveBazelWorkspace",
"bazel.haveWorkspace",
haveBazelWorkspace,
);
}
Expand Down

0 comments on commit bfdafa1

Please sign in to comment.