diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-02 10:42:03 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-02 10:42:03 +0100 |
commit | d8e5265309cf92857c996d4f55372e3b431468bf (patch) | |
tree | 101f5f55c324d7cb7bf3c7ae22a553ca4f7bf66c /editors/code/src | |
parent | 40a028c9a837f4f189b7db82cd4034536af87322 (diff) | |
parent | 4ebacf9024d82349c4b95826a4a791bdf384d0df (diff) |
Merge #5954
5954: Add flexible configuration for runnables r=popzxc a=popzxc
This PR introduces two new configuration options for runnables: `overrideCargo` and `cargoExtraArgs`.
These options are applied to all the "run" tasks of rust analyzer, such as binaries and tests.
Overall motivation is that rust-analyzer provides similar options, for example, for `rustfmt`, but not for runnables.
## `overrideCargo`
This option allows user to replace `cargo` command with something else (well, something that is compatible with the cargo arguments).
Motivation is that some projects may have wrappers around cargo (or even whole alternatives to cargo), which do something related to the project, and only then run `cargo`. With this feature, such users will be able to use lens and run tests directly from the IDE rather than from terminal.
![cargo_override](https://user-images.githubusercontent.com/12111581/92306622-2f404f80-ef99-11ea-9bb7-6c6192a2c54a.gif)
## `cargoExtraArgs`
This option allows user to add any additional arguments for `cargo`, such as `--release`.
It may be useful, for example, if project has big integration tests which take too long in debug mode, or if any other `cargo` flag has to be passed.
![cargo_extra_args](https://user-images.githubusercontent.com/12111581/92306658-821a0700-ef99-11ea-8be9-bf0aff78e154.gif)
Co-authored-by: Igor Aleksanov <[email protected]>
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/lsp_ext.ts | 2 | ||||
-rw-r--r-- | editors/code/src/run.ts | 2 | ||||
-rw-r--r-- | editors/code/src/tasks.ts | 10 |
3 files changed, 13 insertions, 1 deletions
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 { | |||
69 | args: { | 69 | args: { |
70 | workspaceRoot?: string; | 70 | workspaceRoot?: string; |
71 | cargoArgs: string[]; | 71 | cargoArgs: string[]; |
72 | cargoExtraArgs: string[]; | ||
72 | executableArgs: string[]; | 73 | executableArgs: string[]; |
73 | expectTest?: boolean; | 74 | expectTest?: boolean; |
75 | overrideCargo?: string; | ||
74 | }; | 76 | }; |
75 | } | 77 | } |
76 | export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables"); | 78 | export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("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 | |||
129 | } | 129 | } |
130 | 130 | ||
131 | const args = [...runnable.args.cargoArgs]; // should be a copy! | 131 | const args = [...runnable.args.cargoArgs]; // should be a copy! |
132 | args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options. | ||
132 | if (runnable.args.executableArgs.length > 0) { | 133 | if (runnable.args.executableArgs.length > 0) { |
133 | args.push('--', ...runnable.args.executableArgs); | 134 | args.push('--', ...runnable.args.executableArgs); |
134 | } | 135 | } |
@@ -139,6 +140,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise | |||
139 | args: args.slice(1), | 140 | args: args.slice(1), |
140 | cwd: runnable.args.workspaceRoot || ".", | 141 | cwd: runnable.args.workspaceRoot || ".", |
141 | env: prepareEnv(runnable, config.runnableEnv), | 142 | env: prepareEnv(runnable, config.runnableEnv), |
143 | overrideCargo: runnable.args.overrideCargo, | ||
142 | }; | 144 | }; |
143 | 145 | ||
144 | const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate() | 146 | 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 { | |||
13 | args?: string[]; | 13 | args?: string[]; |
14 | cwd?: string; | 14 | cwd?: string; |
15 | env?: { [key: string]: string }; | 15 | env?: { [key: string]: string }; |
16 | overrideCargo?: string; | ||
16 | } | 17 | } |
17 | 18 | ||
18 | class CargoTaskProvider implements vscode.TaskProvider { | 19 | class CargoTaskProvider implements vscode.TaskProvider { |
@@ -98,7 +99,14 @@ export async function buildCargoTask( | |||
98 | } | 99 | } |
99 | 100 | ||
100 | if (!exec) { | 101 | if (!exec) { |
101 | exec = new vscode.ShellExecution(toolchain.cargoPath(), args, definition); | 102 | // Check whether we must use a user-defined substitute for cargo. |
103 | const cargoCommand = definition.overrideCargo ? definition.overrideCargo : toolchain.cargoPath(); | ||
104 | |||
105 | // Prepare the whole command as one line. It is required if user has provided override command which contains spaces, | ||
106 | // for example "wrapper cargo". Without manual preparation the overridden command will be quoted and fail to execute. | ||
107 | const fullCommand = [cargoCommand, ...args].join(" "); | ||
108 | |||
109 | exec = new vscode.ShellExecution(fullCommand, definition); | ||
102 | } | 110 | } |
103 | 111 | ||
104 | return new vscode.Task( | 112 | return new vscode.Task( |