diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-28 14:37:37 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-28 14:37:37 +0100 |
commit | 190a0595a478d059fdd95a179fe38d59cb6379be (patch) | |
tree | 24b22bf8c212df5b6bc6c8ba493d2d7171b24b7f /editors/code/src/main.ts | |
parent | fc29d0e9248bf36c6e47f54f41e90a288729b1a7 (diff) | |
parent | 6d0f1e2e7209e85c1c558bd712d22e359f1f2786 (diff) |
Merge #4640
4640: Add `inRustProject` when-clause for commands in vscode r=vsrs a=vsrs
At the moment all rust-analyzer commands always visible in the command palette, even if there is no rust project opened.
This PR adds special [when-clause](https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts) context. This context also might be used in key bindings.
Co-authored-by: vsrs <[email protected]>
Co-authored-by: vsrs <[email protected]>
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r-- | editors/code/src/main.ts | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 31ac81ee8..b7337621c 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -12,10 +12,13 @@ import { log, assert, isValidExecutable } from './util'; | |||
12 | import { PersistentState } from './persistent_state'; | 12 | import { PersistentState } from './persistent_state'; |
13 | import { fetchRelease, download } from './net'; | 13 | import { fetchRelease, download } from './net'; |
14 | import { activateTaskProvider } from './tasks'; | 14 | import { activateTaskProvider } from './tasks'; |
15 | import { setContextValue } from './util'; | ||
15 | import { exec } from 'child_process'; | 16 | import { exec } from 'child_process'; |
16 | 17 | ||
17 | let ctx: Ctx | undefined; | 18 | let ctx: Ctx | undefined; |
18 | 19 | ||
20 | const RUST_PROJECT_CONTEXT_NAME = "inRustProject"; | ||
21 | |||
19 | export async function activate(context: vscode.ExtensionContext) { | 22 | export async function activate(context: vscode.ExtensionContext) { |
20 | // Register a "dumb" onEnter command for the case where server fails to | 23 | // Register a "dumb" onEnter command for the case where server fails to |
21 | // start. | 24 | // start. |
@@ -54,6 +57,8 @@ export async function activate(context: vscode.ExtensionContext) { | |||
54 | // This a horribly, horribly wrong way to deal with this problem. | 57 | // This a horribly, horribly wrong way to deal with this problem. |
55 | ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath); | 58 | ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath); |
56 | 59 | ||
60 | setContextValue(RUST_PROJECT_CONTEXT_NAME, true); | ||
61 | |||
57 | // Commands which invokes manually via command palette, shortcut, etc. | 62 | // Commands which invokes manually via command palette, shortcut, etc. |
58 | 63 | ||
59 | // Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895 | 64 | // Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895 |
@@ -109,6 +114,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
109 | } | 114 | } |
110 | 115 | ||
111 | export async function deactivate() { | 116 | export async function deactivate() { |
117 | setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined); | ||
112 | await ctx?.client.stop(); | 118 | await ctx?.client.stop(); |
113 | ctx = undefined; | 119 | ctx = undefined; |
114 | } | 120 | } |