aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorIgor Aleksanov <[email protected]>2020-09-05 14:21:14 +0100
committerIgor Aleksanov <[email protected]>2020-10-02 10:35:22 +0100
commit5b26629a4d8ca388db1b272a7c8b8ea37f45c9f9 (patch)
tree6d056f5658df00cff3c4acadf73d80f7d832d915 /editors/code
parent4a1b4b23bb58398a7e2a955e0be43ff2c09fe9e5 (diff)
Support 'runnables' options in the vs code extension
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package.json16
-rw-r--r--editors/code/src/lsp_ext.ts2
-rw-r--r--editors/code/src/run.ts2
-rw-r--r--editors/code/src/tasks.ts10
-rw-r--r--editors/code/tests/unit/runnable_env.test.ts3
5 files changed, 31 insertions, 2 deletions
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 @@
651 ], 651 ],
652 "default": "full", 652 "default": "full",
653 "description": "The strategy to use when inserting new imports or merging imports." 653 "description": "The strategy to use when inserting new imports or merging imports."
654 },
655 "rust-analyzer.runnables.overrideCargo": {
656 "type": [
657 "null",
658 "string"
659 ],
660 "default": null,
661 "description": "Command to be executed instead of 'cargo' for runnables."
662 },
663 "rust-analyzer.runnables.cargoExtraArgs": {
664 "type": "array",
665 "items": {
666 "type": "string"
667 },
668 "default": [],
669 "description": "Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be '--release'"
654 } 670 }
655 } 671 }
656 }, 672 },
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}
76export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables"); 78export 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
18class CargoTaskProvider implements vscode.TaskProvider { 19class 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(
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 {
9 kind: "cargo", 9 kind: "cargo",
10 args: { 10 args: {
11 cargoArgs: [], 11 cargoArgs: [],
12 executableArgs: [] 12 executableArgs: [],
13 cargoExtraArgs: []
13 } 14 }
14 }; 15 };
15} 16}