aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/commands.ts14
-rw-r--r--editors/code/src/main.ts1
-rw-r--r--editors/code/src/run.ts19
4 files changed, 31 insertions, 8 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index e5d439050..55825456e 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -134,6 +134,11 @@
134 "category": "Rust Analyzer" 134 "category": "Rust Analyzer"
135 }, 135 },
136 { 136 {
137 "command": "rust-analyzer.copyRunCommandLine",
138 "title": "Copy Run Command Line",
139 "category": "Rust Analyzer"
140 },
141 {
137 "command": "rust-analyzer.debug", 142 "command": "rust-analyzer.debug",
138 "title": "Debug", 143 "title": "Debug",
139 "category": "Rust Analyzer" 144 "category": "Rust Analyzer"
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index cbda619ea..e3a23c0d2 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -5,7 +5,7 @@ import * as ra from './lsp_ext';
5import { Ctx, Cmd } from './ctx'; 5import { Ctx, Cmd } from './ctx';
6import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets'; 6import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
7import { spawnSync } from 'child_process'; 7import { spawnSync } from 'child_process';
8import { RunnableQuickPick, selectRunnable, createTask } from './run'; 8import { RunnableQuickPick, selectRunnable, createTask, createArgs } 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'; 11import { startDebugSession, makeDebugConfig } from './debug';
@@ -572,6 +572,18 @@ export function runSingle(ctx: Ctx): Cmd {
572 }; 572 };
573} 573}
574 574
575export 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
575export function debug(ctx: Ctx): Cmd { 587export function debug(ctx: Ctx): Cmd {
576 let prevDebuggee: RunnableQuickPick | undefined; 588 let prevDebuggee: RunnableQuickPick | undefined;
577 589
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 1900d900a..43cae5c7f 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -108,6 +108,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
108 ctx.registerCommand('viewHir', commands.viewHir); 108 ctx.registerCommand('viewHir', commands.viewHir);
109 ctx.registerCommand('expandMacro', commands.expandMacro); 109 ctx.registerCommand('expandMacro', commands.expandMacro);
110 ctx.registerCommand('run', commands.run); 110 ctx.registerCommand('run', commands.run);
111 ctx.registerCommand('copyRunCommandLine', commands.copyRunCommandLine);
111 ctx.registerCommand('debug', commands.debug); 112 ctx.registerCommand('debug', commands.debug);
112 ctx.registerCommand('newDebugConfig', commands.newDebugConfig); 113 ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
113 ctx.registerCommand('openDocs', commands.openDocs); 114 ctx.registerCommand('openDocs', commands.openDocs);
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index 17573cd82..f42baed16 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -128,13 +128,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
128 throw `Unexpected runnable kind: ${runnable.kind}`; 128 throw `Unexpected runnable kind: ${runnable.kind}`;
129 } 129 }
130 130
131 const args = [...runnable.args.cargoArgs]; // should be a copy! 131 const args = createArgs(runnable);
132 if (runnable.args.cargoExtraArgs) {
133 args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options.
134 }
135 if (runnable.args.executableArgs.length > 0) {
136 args.push('--', ...runnable.args.executableArgs);
137 }
138 132
139 const definition: tasks.CargoTaskDefinition = { 133 const definition: tasks.CargoTaskDefinition = {
140 type: tasks.TASK_TYPE, 134 type: tasks.TASK_TYPE,
@@ -151,3 +145,14 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
151 145
152 return cargoTask; 146 return cargoTask;
153} 147}
148
149export function createArgs(runnable: ra.Runnable): string[] {
150 const args = [...runnable.args.cargoArgs]; // should be a copy!
151 if (runnable.args.cargoExtraArgs) {
152 args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options.
153 }
154 if (runnable.args.executableArgs.length > 0) {
155 args.push('--', ...runnable.args.executableArgs);
156 }
157 return args;
158}