aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/runnables.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/runnables.ts')
-rw-r--r--editors/code/src/commands/runnables.ts122
1 files changed, 61 insertions, 61 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 7728541de..8cd86c21e 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -1,7 +1,67 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3 3
4import { Server } from '../server'; 4import { Ctx, Cmd } from '../ctx';
5
6export 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
49export 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
6interface RunnablesParams { 66interface 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
71let prevRunnable: RunnableQuickPick | undefined;
72export 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
114export 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}