aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r--editors/code/src/commands.ts93
1 files changed, 77 insertions, 16 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 86302db37..3e9c3aa0e 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -8,6 +8,7 @@ import { spawnSync } from 'child_process';
8import { RunnableQuickPick, selectRunnable, createTask } from './run'; 8import { RunnableQuickPick, selectRunnable, createTask } from './run';
9import { AstInspector } from './ast_inspector'; 9import { AstInspector } from './ast_inspector';
10import { isRustDocument, sleep, isRustEditor } from './util'; 10import { isRustDocument, sleep, isRustEditor } from './util';
11import { startDebugSession, makeDebugConfig } from './debug';
11 12
12export * from './ast_inspector'; 13export * from './ast_inspector';
13export * from './run'; 14export * from './run';
@@ -197,20 +198,6 @@ export function toggleInlayHints(ctx: Ctx): Cmd {
197 }; 198 };
198} 199}
199 200
200export function run(ctx: Ctx): Cmd {
201 let prevRunnable: RunnableQuickPick | undefined;
202
203 return async () => {
204 const item = await selectRunnable(ctx, prevRunnable);
205 if (!item) return;
206
207 item.detail = 'rerun';
208 prevRunnable = item;
209 const task = createTask(item.runnable);
210 return await vscode.tasks.executeTask(task);
211 };
212}
213
214// Opens the virtual file that will show the syntax tree 201// Opens the virtual file that will show the syntax tree
215// 202//
216// The contents of the file come from the `TextDocumentContentProvider` 203// The contents of the file come from the `TextDocumentContentProvider`
@@ -356,10 +343,25 @@ export function showReferences(ctx: Ctx): Cmd {
356} 343}
357 344
358export function applyActionGroup(_ctx: Ctx): Cmd { 345export function applyActionGroup(_ctx: Ctx): Cmd {
359 return async (actions: { label: string; edit: vscode.WorkspaceEdit }[]) => { 346 return async (actions: { label: string; arguments: ra.ResolveCodeActionParams }[]) => {
360 const selectedAction = await vscode.window.showQuickPick(actions); 347 const selectedAction = await vscode.window.showQuickPick(actions);
361 if (!selectedAction) return; 348 if (!selectedAction) return;
362 await applySnippetWorkspaceEdit(selectedAction.edit); 349 vscode.commands.executeCommand(
350 'rust-analyzer.resolveCodeAction',
351 selectedAction.arguments,
352 );
353 };
354}
355
356export function resolveCodeAction(ctx: Ctx): Cmd {
357 const client = ctx.client;
358 return async (params: ra.ResolveCodeActionParams) => {
359 const item: lc.WorkspaceEdit = await client.sendRequest(ra.resolveCodeAction, params);
360 if (!item) {
361 return;
362 }
363 const edit = client.protocol2CodeConverter.asWorkspaceEdit(item);
364 await applySnippetWorkspaceEdit(edit);
363 }; 365 };
364} 366}
365 367
@@ -368,3 +370,62 @@ export function applySnippetWorkspaceEditCommand(_ctx: Ctx): Cmd {
368 await applySnippetWorkspaceEdit(edit); 370 await applySnippetWorkspaceEdit(edit);
369 }; 371 };
370} 372}
373
374export function run(ctx: Ctx): Cmd {
375 let prevRunnable: RunnableQuickPick | undefined;
376
377 return async () => {
378 const item = await selectRunnable(ctx, prevRunnable);
379 if (!item) return;
380
381 item.detail = 'rerun';
382 prevRunnable = item;
383 const task = createTask(item.runnable);
384 return await vscode.tasks.executeTask(task);
385 };
386}
387
388export function runSingle(ctx: Ctx): Cmd {
389 return async (runnable: ra.Runnable) => {
390 const editor = ctx.activeRustEditor;
391 if (!editor) return;
392
393 const task = createTask(runnable);
394 task.group = vscode.TaskGroup.Build;
395 task.presentationOptions = {
396 reveal: vscode.TaskRevealKind.Always,
397 panel: vscode.TaskPanelKind.Dedicated,
398 clear: true,
399 };
400
401 return vscode.tasks.executeTask(task);
402 };
403}
404
405export function debug(ctx: Ctx): Cmd {
406 let prevDebuggee: RunnableQuickPick | undefined;
407
408 return async () => {
409 const item = await selectRunnable(ctx, prevDebuggee, true);
410 if (!item) return;
411
412 item.detail = 'restart';
413 prevDebuggee = item;
414 return await startDebugSession(ctx, item.runnable);
415 };
416}
417
418export function debugSingle(ctx: Ctx): Cmd {
419 return async (config: ra.Runnable) => {
420 await startDebugSession(ctx, config);
421 };
422}
423
424export function newDebugConfig(ctx: Ctx): Cmd {
425 return async () => {
426 const item = await selectRunnable(ctx, undefined, true, false);
427 if (!item) return;
428
429 await makeDebugConfig(ctx, item.runnable);
430 };
431}