Skip to content

Commit 0b4187e

Browse files
bors[bot]matklad
andauthored
Merge #7625
7625: Add **Copy Run Command Line** command for vscode r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 5e39d7a + 8d2e827 commit 0b4187e

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@
133133
"title": "Run",
134134
"category": "Rust Analyzer"
135135
},
136+
{
137+
"command": "rust-analyzer.copyRunCommandLine",
138+
"title": "Copy Run Command Line",
139+
"category": "Rust Analyzer"
140+
},
136141
{
137142
"command": "rust-analyzer.debug",
138143
"title": "Debug",

editors/code/src/commands.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as ra from './lsp_ext';
55
import { Ctx, Cmd } from './ctx';
66
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
77
import { spawnSync } from 'child_process';
8-
import { RunnableQuickPick, selectRunnable, createTask } from './run';
8+
import { RunnableQuickPick, selectRunnable, createTask, createArgs } from './run';
99
import { AstInspector } from './ast_inspector';
1010
import { isRustDocument, sleep, isRustEditor } from './util';
1111
import { startDebugSession, makeDebugConfig } from './debug';
@@ -572,6 +572,18 @@ export function runSingle(ctx: Ctx): Cmd {
572572
};
573573
}
574574

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+
575587
export function debug(ctx: Ctx): Cmd {
576588
let prevDebuggee: RunnableQuickPick | undefined;
577589

editors/code/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
108108
ctx.registerCommand('viewHir', commands.viewHir);
109109
ctx.registerCommand('expandMacro', commands.expandMacro);
110110
ctx.registerCommand('run', commands.run);
111+
ctx.registerCommand('copyRunCommandLine', commands.copyRunCommandLine);
111112
ctx.registerCommand('debug', commands.debug);
112113
ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
113114
ctx.registerCommand('openDocs', commands.openDocs);

editors/code/src/run.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
128128
throw `Unexpected runnable kind: ${runnable.kind}`;
129129
}
130130

131-
const args = [...runnable.args.cargoArgs]; // should be a copy!
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-
}
131+
const args = createArgs(runnable)
138132

139133
const definition: tasks.CargoTaskDefinition = {
140134
type: tasks.TASK_TYPE,
@@ -152,3 +146,14 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
152146

153147
return cargoTask;
154148
}
149+
150+
export function createArgs(runnable: ra.Runnable): string[] {
151+
const args = [...runnable.args.cargoArgs]; // should be a copy!
152+
if (runnable.args.cargoExtraArgs) {
153+
args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options.
154+
}
155+
if (runnable.args.executableArgs.length > 0) {
156+
args.push('--', ...runnable.args.executableArgs);
157+
}
158+
return args;
159+
}

0 commit comments

Comments
 (0)