Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add **Copy Run Command Line** command for vscode #7625

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@
"title": "Run",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.copyRunCommandLine",
"title": "Copy Run Command Line",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.debug",
"title": "Debug",
Expand Down
14 changes: 13 additions & 1 deletion editors/code/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as ra from './lsp_ext';
import { Ctx, Cmd } from './ctx';
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
import { spawnSync } from 'child_process';
import { RunnableQuickPick, selectRunnable, createTask } from './run';
import { RunnableQuickPick, selectRunnable, createTask, createArgs } from './run';
import { AstInspector } from './ast_inspector';
import { isRustDocument, sleep, isRustEditor } from './util';
import { startDebugSession, makeDebugConfig } from './debug';
Expand Down Expand Up @@ -572,6 +572,18 @@ export function runSingle(ctx: Ctx): Cmd {
};
}

export function copyRunCommandLine(ctx: Ctx) {
let prevRunnable: RunnableQuickPick | undefined;
return async () => {
const item = await selectRunnable(ctx, prevRunnable);
if (!item) return;
const args = createArgs(item.runnable);
const commandLine = ["cargo", ...args].join(" ");
await vscode.env.clipboard.writeText(commandLine);
await vscode.window.showInformationMessage("Cargo invocation copied to the clipboard.");
};
}

export function debug(ctx: Ctx): Cmd {
let prevDebuggee: RunnableQuickPick | undefined;

Expand Down
1 change: 1 addition & 0 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
ctx.registerCommand('viewHir', commands.viewHir);
ctx.registerCommand('expandMacro', commands.expandMacro);
ctx.registerCommand('run', commands.run);
ctx.registerCommand('copyRunCommandLine', commands.copyRunCommandLine);
ctx.registerCommand('debug', commands.debug);
ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
ctx.registerCommand('openDocs', commands.openDocs);
Expand Down
19 changes: 12 additions & 7 deletions editors/code/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
throw `Unexpected runnable kind: ${runnable.kind}`;
}

const args = [...runnable.args.cargoArgs]; // should be a copy!
if (runnable.args.cargoExtraArgs) {
args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options.
}
if (runnable.args.executableArgs.length > 0) {
args.push('--', ...runnable.args.executableArgs);
}
const args = createArgs(runnable);

const definition: tasks.CargoTaskDefinition = {
type: tasks.TASK_TYPE,
Expand All @@ -151,3 +145,14 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise

return cargoTask;
}

export function createArgs(runnable: ra.Runnable): string[] {
const args = [...runnable.args.cargoArgs]; // should be a copy!
if (runnable.args.cargoExtraArgs) {
args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options.
}
if (runnable.args.executableArgs.length > 0) {
args.push('--', ...runnable.args.executableArgs);
}
return args;
}