diff options
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r-- | editors/code/src/commands.ts | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index c1c9f9754..283b9a160 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -5,7 +5,7 @@ import * as ra from './lsp_ext'; | |||
5 | import { Ctx, Cmd } from './ctx'; | 5 | import { Ctx, Cmd } from './ctx'; |
6 | import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets'; | 6 | import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets'; |
7 | import { spawnSync } from 'child_process'; | 7 | import { spawnSync } from 'child_process'; |
8 | import { RunnableQuickPick, selectRunnable, createTask } from './run'; | 8 | import { RunnableQuickPick, selectRunnable, createTask, createArgs } 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 | import { startDebugSession, makeDebugConfig } from './debug'; |
@@ -125,7 +125,7 @@ export function joinLines(ctx: Ctx): Cmd { | |||
125 | ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)), | 125 | ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)), |
126 | textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document), | 126 | textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document), |
127 | }); | 127 | }); |
128 | editor.edit((builder) => { | 128 | await editor.edit((builder) => { |
129 | client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => { | 129 | client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => { |
130 | builder.replace(edit.range, edit.newText); | 130 | builder.replace(edit.range, edit.newText); |
131 | }); | 131 | }); |
@@ -236,7 +236,7 @@ export function ssr(ctx: Ctx): Cmd { | |||
236 | const request = await vscode.window.showInputBox(options); | 236 | const request = await vscode.window.showInputBox(options); |
237 | if (!request) return; | 237 | if (!request) return; |
238 | 238 | ||
239 | vscode.window.withProgress({ | 239 | await vscode.window.withProgress({ |
240 | location: vscode.ProgressLocation.Notification, | 240 | location: vscode.ProgressLocation.Notification, |
241 | title: "Structured search replace in progress...", | 241 | title: "Structured search replace in progress...", |
242 | cancellable: false, | 242 | cancellable: false, |
@@ -457,10 +457,10 @@ export function reloadWorkspace(ctx: Ctx): Cmd { | |||
457 | } | 457 | } |
458 | 458 | ||
459 | export function showReferences(ctx: Ctx): Cmd { | 459 | export function showReferences(ctx: Ctx): Cmd { |
460 | return (uri: string, position: lc.Position, locations: lc.Location[]) => { | 460 | return async (uri: string, position: lc.Position, locations: lc.Location[]) => { |
461 | const client = ctx.client; | 461 | const client = ctx.client; |
462 | if (client) { | 462 | if (client) { |
463 | vscode.commands.executeCommand( | 463 | await vscode.commands.executeCommand( |
464 | 'editor.action.showReferences', | 464 | 'editor.action.showReferences', |
465 | vscode.Uri.parse(uri), | 465 | vscode.Uri.parse(uri), |
466 | client.protocol2CodeConverter.asPosition(position), | 466 | client.protocol2CodeConverter.asPosition(position), |
@@ -474,7 +474,7 @@ export function applyActionGroup(_ctx: Ctx): Cmd { | |||
474 | return async (actions: { label: string; arguments: lc.CodeAction }[]) => { | 474 | return async (actions: { label: string; arguments: lc.CodeAction }[]) => { |
475 | const selectedAction = await vscode.window.showQuickPick(actions); | 475 | const selectedAction = await vscode.window.showQuickPick(actions); |
476 | if (!selectedAction) return; | 476 | if (!selectedAction) return; |
477 | vscode.commands.executeCommand( | 477 | await vscode.commands.executeCommand( |
478 | 'rust-analyzer.resolveCodeAction', | 478 | 'rust-analyzer.resolveCodeAction', |
479 | selectedAction.arguments, | 479 | selectedAction.arguments, |
480 | ); | 480 | ); |
@@ -510,7 +510,7 @@ export function openDocs(ctx: Ctx): Cmd { | |||
510 | const doclink = await client.sendRequest(ra.openDocs, { position, textDocument }); | 510 | const doclink = await client.sendRequest(ra.openDocs, { position, textDocument }); |
511 | 511 | ||
512 | if (doclink != null) { | 512 | if (doclink != null) { |
513 | vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink)); | 513 | await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink)); |
514 | } | 514 | } |
515 | }; | 515 | }; |
516 | 516 | ||
@@ -528,10 +528,10 @@ export function resolveCodeAction(ctx: Ctx): Cmd { | |||
528 | const edit = client.protocol2CodeConverter.asWorkspaceEdit(itemEdit); | 528 | const edit = client.protocol2CodeConverter.asWorkspaceEdit(itemEdit); |
529 | // filter out all text edits and recreate the WorkspaceEdit without them so we can apply | 529 | // filter out all text edits and recreate the WorkspaceEdit without them so we can apply |
530 | // snippet edits on our own | 530 | // snippet edits on our own |
531 | const itemEditWithoutTextEdits = { ...item, documentChanges: itemEdit.documentChanges?.filter(change => "kind" in change) }; | 531 | const lcFileSystemEdit = { ...itemEdit, documentChanges: itemEdit.documentChanges?.filter(change => "kind" in change) }; |
532 | const editWithoutTextEdits = client.protocol2CodeConverter.asWorkspaceEdit(itemEditWithoutTextEdits); | 532 | const fileSystemEdit = client.protocol2CodeConverter.asWorkspaceEdit(lcFileSystemEdit); |
533 | await vscode.workspace.applyEdit(fileSystemEdit); | ||
533 | await applySnippetWorkspaceEdit(edit); | 534 | await applySnippetWorkspaceEdit(edit); |
534 | await vscode.workspace.applyEdit(editWithoutTextEdits); | ||
535 | }; | 535 | }; |
536 | } | 536 | } |
537 | 537 | ||
@@ -572,6 +572,18 @@ export function runSingle(ctx: Ctx): Cmd { | |||
572 | }; | 572 | }; |
573 | } | 573 | } |
574 | 574 | ||
575 | export function copyRunCommandLine(ctx: Ctx) { | ||
576 | let prevRunnable: RunnableQuickPick | undefined; | ||
577 | return async () => { | ||
578 | const item = await selectRunnable(ctx, prevRunnable); | ||
579 | if (!item) return; | ||
580 | const args = createArgs(item.runnable); | ||
581 | const commandLine = ["cargo", ...args].join(" "); | ||
582 | await vscode.env.clipboard.writeText(commandLine); | ||
583 | await vscode.window.showInformationMessage("Cargo invocation copied to the clipboard."); | ||
584 | }; | ||
585 | } | ||
586 | |||
575 | export function debug(ctx: Ctx): Cmd { | 587 | export function debug(ctx: Ctx): Cmd { |
576 | let prevDebuggee: RunnableQuickPick | undefined; | 588 | let prevDebuggee: RunnableQuickPick | undefined; |
577 | 589 | ||