mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Merge #7625
7625: Add **Copy Run Command Line** command for vscode r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
82a1b91f20
4 changed files with 31 additions and 8 deletions
|
@ -133,6 +133,11 @@
|
||||||
"title": "Run",
|
"title": "Run",
|
||||||
"category": "Rust Analyzer"
|
"category": "Rust Analyzer"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "rust-analyzer.copyRunCommandLine",
|
||||||
|
"title": "Copy Run Command Line",
|
||||||
|
"category": "Rust Analyzer"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "rust-analyzer.debug",
|
"command": "rust-analyzer.debug",
|
||||||
"title": "Debug",
|
"title": "Debug",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import * as ra from './lsp_ext';
|
||||||
import { Ctx, Cmd } from './ctx';
|
import { Ctx, Cmd } from './ctx';
|
||||||
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
|
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
|
||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
import { RunnableQuickPick, selectRunnable, createTask } from './run';
|
import { RunnableQuickPick, selectRunnable, createTask, createArgs } from './run';
|
||||||
import { AstInspector } from './ast_inspector';
|
import { AstInspector } from './ast_inspector';
|
||||||
import { isRustDocument, sleep, isRustEditor } from './util';
|
import { isRustDocument, sleep, isRustEditor } from './util';
|
||||||
import { startDebugSession, makeDebugConfig } from './debug';
|
import { startDebugSession, makeDebugConfig } from './debug';
|
||||||
|
@ -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 {
|
export function debug(ctx: Ctx): Cmd {
|
||||||
let prevDebuggee: RunnableQuickPick | undefined;
|
let prevDebuggee: RunnableQuickPick | undefined;
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
|
||||||
ctx.registerCommand('viewHir', commands.viewHir);
|
ctx.registerCommand('viewHir', commands.viewHir);
|
||||||
ctx.registerCommand('expandMacro', commands.expandMacro);
|
ctx.registerCommand('expandMacro', commands.expandMacro);
|
||||||
ctx.registerCommand('run', commands.run);
|
ctx.registerCommand('run', commands.run);
|
||||||
|
ctx.registerCommand('copyRunCommandLine', commands.copyRunCommandLine);
|
||||||
ctx.registerCommand('debug', commands.debug);
|
ctx.registerCommand('debug', commands.debug);
|
||||||
ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
|
ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
|
||||||
ctx.registerCommand('openDocs', commands.openDocs);
|
ctx.registerCommand('openDocs', commands.openDocs);
|
||||||
|
|
|
@ -128,13 +128,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
|
||||||
throw `Unexpected runnable kind: ${runnable.kind}`;
|
throw `Unexpected runnable kind: ${runnable.kind}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = [...runnable.args.cargoArgs]; // should be a copy!
|
const args = createArgs(runnable);
|
||||||
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 definition: tasks.CargoTaskDefinition = {
|
const definition: tasks.CargoTaskDefinition = {
|
||||||
type: tasks.TASK_TYPE,
|
type: tasks.TASK_TYPE,
|
||||||
|
@ -152,3 +146,14 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
|
||||||
|
|
||||||
return cargoTask;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue