diff options
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r-- | editors/code/src/commands.ts | 93 |
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'; | |||
8 | import { RunnableQuickPick, selectRunnable, createTask } from './run'; | 8 | import { RunnableQuickPick, selectRunnable, createTask } from './run'; |
9 | import { AstInspector } from './ast_inspector'; | 9 | import { AstInspector } from './ast_inspector'; |
10 | import { isRustDocument, sleep, isRustEditor } from './util'; | 10 | import { isRustDocument, sleep, isRustEditor } from './util'; |
11 | import { startDebugSession, makeDebugConfig } from './debug'; | ||
11 | 12 | ||
12 | export * from './ast_inspector'; | 13 | export * from './ast_inspector'; |
13 | export * from './run'; | 14 | export * from './run'; |
@@ -197,20 +198,6 @@ export function toggleInlayHints(ctx: Ctx): Cmd { | |||
197 | }; | 198 | }; |
198 | } | 199 | } |
199 | 200 | ||
200 | export 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 | ||
358 | export function applyActionGroup(_ctx: Ctx): Cmd { | 345 | export 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 | |||
356 | export 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 | |||
374 | export 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 | |||
388 | export 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 | |||
405 | export 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 | |||
418 | export function debugSingle(ctx: Ctx): Cmd { | ||
419 | return async (config: ra.Runnable) => { | ||
420 | await startDebugSession(ctx, config); | ||
421 | }; | ||
422 | } | ||
423 | |||
424 | export 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 | } | ||