diff options
author | vsrs <[email protected]> | 2020-05-27 17:40:13 +0100 |
---|---|---|
committer | vsrs <[email protected]> | 2020-05-27 17:46:23 +0100 |
commit | f3e04fbbabe2887542a9bb57fffcabc7cb50d406 (patch) | |
tree | 2a546bc7eb167a5f996b81831472983742515315 /editors/code | |
parent | 94889b6472b6332436235f6074ebc8ae3ac0ef15 (diff) |
Add `inRustProject` when-clause for commands.
Diffstat (limited to 'editors/code')
-rw-r--r-- | editors/code/package.json | 66 | ||||
-rw-r--r-- | editors/code/src/main.ts | 6 | ||||
-rw-r--r-- | editors/code/src/util.ts | 5 |
3 files changed, 76 insertions, 1 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index acf3ca4b5..75dbafc05 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -694,6 +694,70 @@ | |||
694 | ] | 694 | ] |
695 | } | 695 | } |
696 | } | 696 | } |
697 | ] | 697 | ], |
698 | "menus": { | ||
699 | "commandPalette": [ | ||
700 | { | ||
701 | "command": "rust-analyzer.syntaxTree", | ||
702 | "when": "inRustProject" | ||
703 | }, | ||
704 | { | ||
705 | "command": "rust-analyzer.expandMacro", | ||
706 | "when": "inRustProject" | ||
707 | }, | ||
708 | { | ||
709 | "command": "rust-analyzer.matchingBrace", | ||
710 | "when": "inRustProject" | ||
711 | }, | ||
712 | { | ||
713 | "command": "rust-analyzer.parentModule", | ||
714 | "when": "inRustProject" | ||
715 | }, | ||
716 | { | ||
717 | "command": "rust-analyzer.joinLines", | ||
718 | "when": "inRustProject" | ||
719 | }, | ||
720 | { | ||
721 | "command": "rust-analyzer.run", | ||
722 | "when": "inRustProject" | ||
723 | }, | ||
724 | { | ||
725 | "command": "rust-analyzer.debug", | ||
726 | "when": "inRustProject" | ||
727 | }, | ||
728 | { | ||
729 | "command": "rust-analyzer.newDebugConfig", | ||
730 | "when": "inRustProject" | ||
731 | }, | ||
732 | { | ||
733 | "command": "rust-analyzer.analyzerStatus", | ||
734 | "when": "inRustProject" | ||
735 | }, | ||
736 | { | ||
737 | "command": "rust-analyzer.collectGarbage", | ||
738 | "when": "inRustProject" | ||
739 | }, | ||
740 | { | ||
741 | "command": "rust-analyzer.reload", | ||
742 | "when": "inRustProject" | ||
743 | }, | ||
744 | { | ||
745 | "command": "rust-analyzer.onEnter", | ||
746 | "when": "inRustProject" | ||
747 | }, | ||
748 | { | ||
749 | "command": "rust-analyzer.ssr", | ||
750 | "when": "inRustProject" | ||
751 | }, | ||
752 | { | ||
753 | "command": "rust-analyzer.serverVersion", | ||
754 | "when": "inRustProject" | ||
755 | }, | ||
756 | { | ||
757 | "command": "rust-analyzer.toggleInlayHints", | ||
758 | "when": "inRustProject" | ||
759 | } | ||
760 | ] | ||
761 | } | ||
698 | } | 762 | } |
699 | } | 763 | } |
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 | } |
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 793c481fb..352ef9162 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts | |||
@@ -94,3 +94,8 @@ export function isValidExecutable(path: string): boolean { | |||
94 | 94 | ||
95 | return res.status === 0; | 95 | return res.status === 0; |
96 | } | 96 | } |
97 | |||
98 | /** Sets ['when'](https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts) clause contexts */ | ||
99 | export function setContextValue(key: string, value: any): Thenable<void> { | ||
100 | return vscode.commands.executeCommand('setContext', key, value); | ||
101 | } | ||