From 5b26629a4d8ca388db1b272a7c8b8ea37f45c9f9 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sat, 5 Sep 2020 16:21:14 +0300 Subject: Support 'runnables' options in the vs code extension --- editors/code/package.json | 16 ++++++++++++++++ editors/code/src/lsp_ext.ts | 2 ++ editors/code/src/run.ts | 2 ++ editors/code/src/tasks.ts | 10 +++++++++- editors/code/tests/unit/runnable_env.test.ts | 3 ++- 5 files changed, 31 insertions(+), 2 deletions(-) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index bdd8a0c29..cc2ac3bd2 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -651,6 +651,22 @@ ], "default": "full", "description": "The strategy to use when inserting new imports or merging imports." + }, + "rust-analyzer.runnables.overrideCargo": { + "type": [ + "null", + "string" + ], + "default": null, + "description": "Command to be executed instead of 'cargo' for runnables." + }, + "rust-analyzer.runnables.cargoExtraArgs": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be '--release'" } } }, diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index eb422d3e7..f286b68a6 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -69,8 +69,10 @@ export interface Runnable { args: { workspaceRoot?: string; cargoArgs: string[]; + cargoExtraArgs: string[]; executableArgs: string[]; expectTest?: boolean; + overrideCargo?: string; }; } export const runnables = new lc.RequestType("experimental/runnables"); diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index de68f27ae..459b7f250 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -129,6 +129,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise } const args = [...runnable.args.cargoArgs]; // should be a copy! + args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options. if (runnable.args.executableArgs.length > 0) { args.push('--', ...runnable.args.executableArgs); } @@ -139,6 +140,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise args: args.slice(1), cwd: runnable.args.workspaceRoot || ".", env: prepareEnv(runnable, config.runnableEnv), + overrideCargo: runnable.args.overrideCargo, }; const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate() diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts index 14abbd5b7..a3ff15102 100644 --- a/editors/code/src/tasks.ts +++ b/editors/code/src/tasks.ts @@ -13,6 +13,7 @@ export interface CargoTaskDefinition extends vscode.TaskDefinition { args?: string[]; cwd?: string; env?: { [key: string]: string }; + overrideCargo?: string; } class CargoTaskProvider implements vscode.TaskProvider { @@ -98,7 +99,14 @@ export async function buildCargoTask( } if (!exec) { - exec = new vscode.ShellExecution(toolchain.cargoPath(), args, definition); + // Check whether we must use a user-defined substitute for cargo. + const cargoCommand = definition.overrideCargo ? definition.overrideCargo : toolchain.cargoPath(); + + // Prepare the whole command as one line. It is required if user has provided override command which contains spaces, + // for example "wrapper cargo". Without manual preparation the overridden command will be quoted and fail to execute. + const fullCommand = [cargoCommand, ...args].join(" "); + + exec = new vscode.ShellExecution(fullCommand, definition); } return new vscode.Task( diff --git a/editors/code/tests/unit/runnable_env.test.ts b/editors/code/tests/unit/runnable_env.test.ts index f2f53e91a..c5600cf64 100644 --- a/editors/code/tests/unit/runnable_env.test.ts +++ b/editors/code/tests/unit/runnable_env.test.ts @@ -9,7 +9,8 @@ function makeRunnable(label: string): ra.Runnable { kind: "cargo", args: { cargoArgs: [], - executableArgs: [] + executableArgs: [], + cargoExtraArgs: [] } }; } -- cgit v1.2.3