From 15793a40abb6127cbe08b53827440f6938a09369 Mon Sep 17 00:00:00 2001 From: Adrian Vogelsgesang Date: Tue, 27 Feb 2024 18:43:33 +0100 Subject: [PATCH] Enable the "Restart LSP" command only if a LSP is configured (#345) 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. --- package.json | 23 ++++++++++--------- src/extension/extension.ts | 2 ++ .../bazel_workspace_tree_provider.ts | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 0ac93834..39d8afd3 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,8 @@ { "category": "Bazel", "command": "bazel.lsp.restart", - "title": "Restart language server" + "title": "Restart language server", + "when": "bazel.lsp.enabled" } ], "configuration": { @@ -309,39 +310,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": [ @@ -438,7 +439,7 @@ { "id": "bazelWorkspace", "name": "Bazel Build Targets", - "when": "vscodeBazelHaveBazelWorkspace" + "when": "bazel.haveWorkspace" } ] } diff --git a/src/extension/extension.ts b/src/extension/extension.ts index 147a6bc7..2e4e0c85 100644 --- a/src/extension/extension.ts +++ b/src/extension/extension.ts @@ -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( diff --git a/src/workspace-tree/bazel_workspace_tree_provider.ts b/src/workspace-tree/bazel_workspace_tree_provider.ts index b283147a..b4968e3c 100644 --- a/src/workspace-tree/bazel_workspace_tree_provider.ts +++ b/src/workspace-tree/bazel_workspace_tree_provider.ts @@ -151,7 +151,7 @@ export class BazelWorkspaceTreeProvider // eslint-disable-next-line @typescript-eslint/no-floating-promises vscode.commands.executeCommand( "setContext", - "vscodeBazelHaveBazelWorkspace", + "bazel.haveWorkspace", haveBazelWorkspace, ); }