about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorIgor Aleksanov <popzxc@yandex.ru>2020-09-05 16:21:14 +0300
committerIgor Aleksanov <popzxc@yandex.ru>2020-10-02 12:35:22 +0300
commit5b26629a4d8ca388db1b272a7c8b8ea37f45c9f9 (patch)
tree6d056f5658df00cff3c4acadf73d80f7d832d915 /editors/code
parent4a1b4b23bb58398a7e2a955e0be43ff2c09fe9e5 (diff)
downloadrust-5b26629a4d8ca388db1b272a7c8b8ea37f45c9f9.tar.gz
rust-5b26629a4d8ca388db1b272a7c8b8ea37f45c9f9.zip
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 bdd8a0c298f..cc2ac3bd269 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 eb422d3e759..f286b68a685 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<RunnablesParams, Runnable[], void>("experimental/runnables");
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index de68f27aec5..459b7f250d2 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 14abbd5b794..a3ff1510256 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 f2f53e91ad9..c5600cf64f3 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: []
         }
     };
 }