diff options
author | Aleksey Kladov <[email protected]> | 2019-12-30 19:07:04 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-30 19:07:04 +0000 |
commit | 3d008a78d0ab1d43629326d58d4b2a157303dd00 (patch) | |
tree | 393c5cb5ad9249409808dc46cc7a344b79958ab1 | |
parent | da80b6c1e1c09831b2f30233ddacaf50fa58f812 (diff) |
Move all commands to ctx
-rw-r--r-- | editors/code/src/commands/index.ts | 17 | ||||
-rw-r--r-- | editors/code/src/commands/runnables.ts | 8 | ||||
-rw-r--r-- | editors/code/src/main.ts | 23 |
3 files changed, 26 insertions, 22 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 9f4636e52..4a2e8e4db 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -1,3 +1,6 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | import * as lc from 'vscode-languageclient'; | ||
3 | |||
1 | import { Ctx, Cmd } from '../ctx'; | 4 | import { Ctx, Cmd } from '../ctx'; |
2 | 5 | ||
3 | import { analyzerStatus } from './analyzer_status'; | 6 | import { analyzerStatus } from './analyzer_status'; |
@@ -16,6 +19,17 @@ function collectGarbage(ctx: Ctx): Cmd { | |||
16 | }; | 19 | }; |
17 | } | 20 | } |
18 | 21 | ||
22 | function showReferences(ctx: Ctx): Cmd { | ||
23 | return (uri: string, position: lc.Position, locations: lc.Location[]) => { | ||
24 | vscode.commands.executeCommand( | ||
25 | 'editor.action.showReferences', | ||
26 | vscode.Uri.parse(uri), | ||
27 | ctx.client.protocol2CodeConverter.asPosition(position), | ||
28 | locations.map(ctx.client.protocol2CodeConverter.asLocation), | ||
29 | ); | ||
30 | }; | ||
31 | } | ||
32 | |||
19 | export { | 33 | export { |
20 | analyzerStatus, | 34 | analyzerStatus, |
21 | expandMacro, | 35 | expandMacro, |
@@ -27,5 +41,6 @@ export { | |||
27 | inlayHints, | 41 | inlayHints, |
28 | collectGarbage, | 42 | collectGarbage, |
29 | run, | 43 | run, |
30 | runSingle | 44 | runSingle, |
45 | showReferences, | ||
31 | }; | 46 | }; |
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index c4be21a0c..8cd86c21e 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -8,7 +8,7 @@ export function run(ctx: Ctx): Cmd { | |||
8 | 8 | ||
9 | return async () => { | 9 | return async () => { |
10 | const editor = ctx.activeRustEditor; | 10 | const editor = ctx.activeRustEditor; |
11 | if (!editor) return | 11 | if (!editor) return; |
12 | 12 | ||
13 | const textDocument: lc.TextDocumentIdentifier = { | 13 | const textDocument: lc.TextDocumentIdentifier = { |
14 | uri: editor.document.uri.toString(), | 14 | uri: editor.document.uri.toString(), |
@@ -43,13 +43,13 @@ export function run(ctx: Ctx): Cmd { | |||
43 | prevRunnable = item; | 43 | prevRunnable = item; |
44 | const task = createTask(item.runnable); | 44 | const task = createTask(item.runnable); |
45 | return await vscode.tasks.executeTask(task); | 45 | return await vscode.tasks.executeTask(task); |
46 | } | 46 | }; |
47 | } | 47 | } |
48 | 48 | ||
49 | export function runSingle(ctx: Ctx): Cmd { | 49 | export function runSingle(ctx: Ctx): Cmd { |
50 | return async (runnable: Runnable) => { | 50 | return async (runnable: Runnable) => { |
51 | const editor = ctx.activeRustEditor; | 51 | const editor = ctx.activeRustEditor; |
52 | if (!editor) return | 52 | if (!editor) return; |
53 | 53 | ||
54 | const task = createTask(runnable); | 54 | const task = createTask(runnable); |
55 | task.group = vscode.TaskGroup.Build; | 55 | task.group = vscode.TaskGroup.Build; |
@@ -60,7 +60,7 @@ export function runSingle(ctx: Ctx): Cmd { | |||
60 | }; | 60 | }; |
61 | 61 | ||
62 | return vscode.tasks.executeTask(task); | 62 | return vscode.tasks.executeTask(task); |
63 | } | 63 | }; |
64 | } | 64 | } |
65 | 65 | ||
66 | interface RunnablesParams { | 66 | interface RunnablesParams { |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 7ad5e6934..4a3e1ab7c 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -13,6 +13,8 @@ let ctx!: Ctx; | |||
13 | 13 | ||
14 | export async function activate(context: vscode.ExtensionContext) { | 14 | export async function activate(context: vscode.ExtensionContext) { |
15 | ctx = new Ctx(context); | 15 | ctx = new Ctx(context); |
16 | |||
17 | // Commands which invokes manually via command pallet, shortcut, etc. | ||
16 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); | 18 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); |
17 | ctx.registerCommand('collectGarbage', commands.collectGarbage); | 19 | ctx.registerCommand('collectGarbage', commands.collectGarbage); |
18 | ctx.registerCommand('matchingBrace', commands.matchingBrace); | 20 | ctx.registerCommand('matchingBrace', commands.matchingBrace); |
@@ -21,28 +23,15 @@ export async function activate(context: vscode.ExtensionContext) { | |||
21 | ctx.registerCommand('syntaxTree', commands.syntaxTree); | 23 | ctx.registerCommand('syntaxTree', commands.syntaxTree); |
22 | ctx.registerCommand('expandMacro', commands.expandMacro); | 24 | ctx.registerCommand('expandMacro', commands.expandMacro); |
23 | ctx.registerCommand('run', commands.run); | 25 | ctx.registerCommand('run', commands.run); |
24 | ctx.registerCommand('runSingle', commands.runSingle); // Internal action for lenses | 26 | |
27 | // Internal commands which are invoked by the server. | ||
28 | ctx.registerCommand('runSingle', commands.runSingle); | ||
29 | ctx.registerCommand('showReferences', commands.showReferences); | ||
25 | 30 | ||
26 | function disposeOnDeactivation(disposable: vscode.Disposable) { | 31 | function disposeOnDeactivation(disposable: vscode.Disposable) { |
27 | context.subscriptions.push(disposable); | 32 | context.subscriptions.push(disposable); |
28 | } | 33 | } |
29 | 34 | ||
30 | function registerCommand(name: string, f: any) { | ||
31 | disposeOnDeactivation(vscode.commands.registerCommand(name, f)); | ||
32 | } | ||
33 | |||
34 | registerCommand( | ||
35 | 'rust-analyzer.showReferences', | ||
36 | (uri: string, position: lc.Position, locations: lc.Location[]) => { | ||
37 | vscode.commands.executeCommand( | ||
38 | 'editor.action.showReferences', | ||
39 | vscode.Uri.parse(uri), | ||
40 | Server.client.protocol2CodeConverter.asPosition(position), | ||
41 | locations.map(Server.client.protocol2CodeConverter.asLocation), | ||
42 | ); | ||
43 | }, | ||
44 | ); | ||
45 | |||
46 | if (Server.config.enableEnhancedTyping) { | 35 | if (Server.config.enableEnhancedTyping) { |
47 | ctx.overrideCommand('type', commands.onEnter); | 36 | ctx.overrideCommand('type', commands.onEnter); |
48 | } | 37 | } |