mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Support 'runnables' options in the vs code extension
This commit is contained in:
parent
4a1b4b23bb
commit
5b26629a4d
5 changed files with 31 additions and 2 deletions
|
@ -651,6 +651,22 @@
|
||||||
],
|
],
|
||||||
"default": "full",
|
"default": "full",
|
||||||
"description": "The strategy to use when inserting new imports or merging imports."
|
"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'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -69,8 +69,10 @@ export interface Runnable {
|
||||||
args: {
|
args: {
|
||||||
workspaceRoot?: string;
|
workspaceRoot?: string;
|
||||||
cargoArgs: string[];
|
cargoArgs: string[];
|
||||||
|
cargoExtraArgs: string[];
|
||||||
executableArgs: string[];
|
executableArgs: string[];
|
||||||
expectTest?: boolean;
|
expectTest?: boolean;
|
||||||
|
overrideCargo?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables");
|
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables");
|
||||||
|
|
|
@ -129,6 +129,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = [...runnable.args.cargoArgs]; // should be a copy!
|
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) {
|
if (runnable.args.executableArgs.length > 0) {
|
||||||
args.push('--', ...runnable.args.executableArgs);
|
args.push('--', ...runnable.args.executableArgs);
|
||||||
}
|
}
|
||||||
|
@ -139,6 +140,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
|
||||||
args: args.slice(1),
|
args: args.slice(1),
|
||||||
cwd: runnable.args.workspaceRoot || ".",
|
cwd: runnable.args.workspaceRoot || ".",
|
||||||
env: prepareEnv(runnable, config.runnableEnv),
|
env: prepareEnv(runnable, config.runnableEnv),
|
||||||
|
overrideCargo: runnable.args.overrideCargo,
|
||||||
};
|
};
|
||||||
|
|
||||||
const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()
|
const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()
|
||||||
|
|
|
@ -13,6 +13,7 @@ export interface CargoTaskDefinition extends vscode.TaskDefinition {
|
||||||
args?: string[];
|
args?: string[];
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
env?: { [key: string]: string };
|
env?: { [key: string]: string };
|
||||||
|
overrideCargo?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CargoTaskProvider implements vscode.TaskProvider {
|
class CargoTaskProvider implements vscode.TaskProvider {
|
||||||
|
@ -98,7 +99,14 @@ export async function buildCargoTask(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exec) {
|
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(
|
return new vscode.Task(
|
||||||
|
|
|
@ -9,7 +9,8 @@ function makeRunnable(label: string): ra.Runnable {
|
||||||
kind: "cargo",
|
kind: "cargo",
|
||||||
args: {
|
args: {
|
||||||
cargoArgs: [],
|
cargoArgs: [],
|
||||||
executableArgs: []
|
executableArgs: [],
|
||||||
|
cargoExtraArgs: []
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue