diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/commands/index.ts | 5 | ||||
-rw-r--r-- | editors/code/src/commands/runnables.ts | 122 | ||||
-rw-r--r-- | editors/code/src/main.ts | 6 |
3 files changed, 66 insertions, 67 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 325ae3da8..9f4636e52 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -8,7 +8,7 @@ import { parentModule } from './parent_module'; | |||
8 | import { syntaxTree } from './syntax_tree'; | 8 | import { syntaxTree } from './syntax_tree'; |
9 | import { expandMacro } from './expand_macro'; | 9 | import { expandMacro } from './expand_macro'; |
10 | import * as inlayHints from './inlay_hints'; | 10 | import * as inlayHints from './inlay_hints'; |
11 | import * as runnables from './runnables'; | 11 | import { run, runSingle } from './runnables'; |
12 | 12 | ||
13 | function collectGarbage(ctx: Ctx): Cmd { | 13 | function collectGarbage(ctx: Ctx): Cmd { |
14 | return async () => { | 14 | return async () => { |
@@ -22,9 +22,10 @@ export { | |||
22 | joinLines, | 22 | joinLines, |
23 | matchingBrace, | 23 | matchingBrace, |
24 | parentModule, | 24 | parentModule, |
25 | runnables, | ||
26 | syntaxTree, | 25 | syntaxTree, |
27 | onEnter, | 26 | onEnter, |
28 | inlayHints, | 27 | inlayHints, |
29 | collectGarbage, | 28 | collectGarbage, |
29 | run, | ||
30 | runSingle | ||
30 | }; | 31 | }; |
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 7728541de..c4be21a0c 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -1,7 +1,67 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | 3 | ||
4 | import { Server } from '../server'; | 4 | import { Ctx, Cmd } from '../ctx'; |
5 | |||
6 | export function run(ctx: Ctx): Cmd { | ||
7 | let prevRunnable: RunnableQuickPick | undefined; | ||
8 | |||
9 | return async () => { | ||
10 | const editor = ctx.activeRustEditor; | ||
11 | if (!editor) return | ||
12 | |||
13 | const textDocument: lc.TextDocumentIdentifier = { | ||
14 | uri: editor.document.uri.toString(), | ||
15 | }; | ||
16 | const params: RunnablesParams = { | ||
17 | textDocument, | ||
18 | position: ctx.client.code2ProtocolConverter.asPosition( | ||
19 | editor.selection.active, | ||
20 | ), | ||
21 | }; | ||
22 | const runnables = await ctx.client.sendRequest<Runnable[]>( | ||
23 | 'rust-analyzer/runnables', | ||
24 | params, | ||
25 | ); | ||
26 | const items: RunnableQuickPick[] = []; | ||
27 | if (prevRunnable) { | ||
28 | items.push(prevRunnable); | ||
29 | } | ||
30 | for (const r of runnables) { | ||
31 | if ( | ||
32 | prevRunnable && | ||
33 | JSON.stringify(prevRunnable.runnable) === JSON.stringify(r) | ||
34 | ) { | ||
35 | continue; | ||
36 | } | ||
37 | items.push(new RunnableQuickPick(r)); | ||
38 | } | ||
39 | const item = await vscode.window.showQuickPick(items); | ||
40 | if (!item) return; | ||
41 | |||
42 | item.detail = 'rerun'; | ||
43 | prevRunnable = item; | ||
44 | const task = createTask(item.runnable); | ||
45 | return await vscode.tasks.executeTask(task); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | export function runSingle(ctx: Ctx): Cmd { | ||
50 | return async (runnable: Runnable) => { | ||
51 | const editor = ctx.activeRustEditor; | ||
52 | if (!editor) return | ||
53 | |||
54 | const task = createTask(runnable); | ||
55 | task.group = vscode.TaskGroup.Build; | ||
56 | task.presentationOptions = { | ||
57 | reveal: vscode.TaskRevealKind.Always, | ||
58 | panel: vscode.TaskPanelKind.Dedicated, | ||
59 | clear: true, | ||
60 | }; | ||
61 | |||
62 | return vscode.tasks.executeTask(task); | ||
63 | } | ||
64 | } | ||
5 | 65 | ||
6 | interface RunnablesParams { | 66 | interface RunnablesParams { |
7 | textDocument: lc.TextDocumentIdentifier; | 67 | textDocument: lc.TextDocumentIdentifier; |
@@ -67,63 +127,3 @@ function createTask(spec: Runnable): vscode.Task { | |||
67 | t.presentationOptions.clear = true; | 127 | t.presentationOptions.clear = true; |
68 | return t; | 128 | return t; |
69 | } | 129 | } |
70 | |||
71 | let prevRunnable: RunnableQuickPick | undefined; | ||
72 | export async function handle(): Promise<vscode.TaskExecution | undefined> { | ||
73 | const editor = vscode.window.activeTextEditor; | ||
74 | if (editor == null || editor.document.languageId !== 'rust') { | ||
75 | return; | ||
76 | } | ||
77 | const textDocument: lc.TextDocumentIdentifier = { | ||
78 | uri: editor.document.uri.toString(), | ||
79 | }; | ||
80 | const params: RunnablesParams = { | ||
81 | textDocument, | ||
82 | position: Server.client.code2ProtocolConverter.asPosition( | ||
83 | editor.selection.active, | ||
84 | ), | ||
85 | }; | ||
86 | const runnables = await Server.client.sendRequest<Runnable[]>( | ||
87 | 'rust-analyzer/runnables', | ||
88 | params, | ||
89 | ); | ||
90 | const items: RunnableQuickPick[] = []; | ||
91 | if (prevRunnable) { | ||
92 | items.push(prevRunnable); | ||
93 | } | ||
94 | for (const r of runnables) { | ||
95 | if ( | ||
96 | prevRunnable && | ||
97 | JSON.stringify(prevRunnable.runnable) === JSON.stringify(r) | ||
98 | ) { | ||
99 | continue; | ||
100 | } | ||
101 | items.push(new RunnableQuickPick(r)); | ||
102 | } | ||
103 | const item = await vscode.window.showQuickPick(items); | ||
104 | if (!item) { | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | item.detail = 'rerun'; | ||
109 | prevRunnable = item; | ||
110 | const task = createTask(item.runnable); | ||
111 | return await vscode.tasks.executeTask(task); | ||
112 | } | ||
113 | |||
114 | export async function handleSingle(runnable: Runnable) { | ||
115 | const editor = vscode.window.activeTextEditor; | ||
116 | if (editor == null || editor.document.languageId !== 'rust') { | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | const task = createTask(runnable); | ||
121 | task.group = vscode.TaskGroup.Build; | ||
122 | task.presentationOptions = { | ||
123 | reveal: vscode.TaskRevealKind.Always, | ||
124 | panel: vscode.TaskPanelKind.Dedicated, | ||
125 | clear: true, | ||
126 | }; | ||
127 | |||
128 | return vscode.tasks.executeTask(task); | ||
129 | } | ||
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index b8e3396a6..7ad5e6934 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -20,6 +20,8 @@ export async function activate(context: vscode.ExtensionContext) { | |||
20 | ctx.registerCommand('parentModule', commands.parentModule); | 20 | ctx.registerCommand('parentModule', commands.parentModule); |
21 | ctx.registerCommand('syntaxTree', commands.syntaxTree); | 21 | ctx.registerCommand('syntaxTree', commands.syntaxTree); |
22 | ctx.registerCommand('expandMacro', commands.expandMacro); | 22 | ctx.registerCommand('expandMacro', commands.expandMacro); |
23 | ctx.registerCommand('run', commands.run); | ||
24 | ctx.registerCommand('runSingle', commands.runSingle); // Internal action for lenses | ||
23 | 25 | ||
24 | function disposeOnDeactivation(disposable: vscode.Disposable) { | 26 | function disposeOnDeactivation(disposable: vscode.Disposable) { |
25 | context.subscriptions.push(disposable); | 27 | context.subscriptions.push(disposable); |
@@ -29,10 +31,6 @@ export async function activate(context: vscode.ExtensionContext) { | |||
29 | disposeOnDeactivation(vscode.commands.registerCommand(name, f)); | 31 | disposeOnDeactivation(vscode.commands.registerCommand(name, f)); |
30 | } | 32 | } |
31 | 33 | ||
32 | // Commands are requests from vscode to the language server | ||
33 | registerCommand('rust-analyzer.run', commands.runnables.handle); | ||
34 | // Unlike the above this does not send requests to the language server | ||
35 | registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); | ||
36 | registerCommand( | 34 | registerCommand( |
37 | 'rust-analyzer.showReferences', | 35 | 'rust-analyzer.showReferences', |
38 | (uri: string, position: lc.Position, locations: lc.Location[]) => { | 36 | (uri: string, position: lc.Position, locations: lc.Location[]) => { |