aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package.json16
-rw-r--r--editors/code/src/commands.ts19
-rw-r--r--editors/code/src/lsp_ext.ts7
-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
6 files changed, 47 insertions, 10 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/commands.ts b/editors/code/src/commands.ts
index e9581a9b5..1a90f1b7d 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -21,7 +21,12 @@ export function analyzerStatus(ctx: Ctx): Cmd {
21 provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> { 21 provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> {
22 if (!vscode.window.activeTextEditor) return ''; 22 if (!vscode.window.activeTextEditor) return '';
23 23
24 return ctx.client.sendRequest(ra.analyzerStatus); 24 const params: ra.AnalyzerStatusParams = {};
25 const doc = ctx.activeRustEditor?.document;
26 if (doc != null) {
27 params.textDocument = ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(doc);
28 }
29 return ctx.client.sendRequest(ra.analyzerStatus, params);
25 } 30 }
26 31
27 get onDidChange(): vscode.Event<vscode.Uri> { 32 get onDidChange(): vscode.Event<vscode.Uri> {
@@ -94,7 +99,7 @@ export function matchingBrace(ctx: Ctx): Cmd {
94 if (!editor || !client) return; 99 if (!editor || !client) return;
95 100
96 const response = await client.sendRequest(ra.matchingBrace, { 101 const response = await client.sendRequest(ra.matchingBrace, {
97 textDocument: { uri: editor.document.uri.toString() }, 102 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
98 positions: editor.selections.map(s => 103 positions: editor.selections.map(s =>
99 client.code2ProtocolConverter.asPosition(s.active), 104 client.code2ProtocolConverter.asPosition(s.active),
100 ), 105 ),
@@ -118,7 +123,7 @@ export function joinLines(ctx: Ctx): Cmd {
118 123
119 const items: lc.TextEdit[] = await client.sendRequest(ra.joinLines, { 124 const items: lc.TextEdit[] = await client.sendRequest(ra.joinLines, {
120 ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)), 125 ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)),
121 textDocument: { uri: editor.document.uri.toString() }, 126 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
122 }); 127 });
123 editor.edit((builder) => { 128 editor.edit((builder) => {
124 client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => { 129 client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => {
@@ -136,7 +141,7 @@ export function onEnter(ctx: Ctx): Cmd {
136 if (!editor || !client) return false; 141 if (!editor || !client) return false;
137 142
138 const lcEdits = await client.sendRequest(ra.onEnter, { 143 const lcEdits = await client.sendRequest(ra.onEnter, {
139 textDocument: { uri: editor.document.uri.toString() }, 144 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
140 position: client.code2ProtocolConverter.asPosition( 145 position: client.code2ProtocolConverter.asPosition(
141 editor.selection.active, 146 editor.selection.active,
142 ), 147 ),
@@ -165,7 +170,7 @@ export function parentModule(ctx: Ctx): Cmd {
165 if (!editor || !client) return; 170 if (!editor || !client) return;
166 171
167 const response = await client.sendRequest(ra.parentModule, { 172 const response = await client.sendRequest(ra.parentModule, {
168 textDocument: { uri: editor.document.uri.toString() }, 173 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
169 position: client.code2ProtocolConverter.asPosition( 174 position: client.code2ProtocolConverter.asPosition(
170 editor.selection.active, 175 editor.selection.active,
171 ), 176 ),
@@ -191,7 +196,7 @@ export function ssr(ctx: Ctx): Cmd {
191 196
192 const position = editor.selection.active; 197 const position = editor.selection.active;
193 const selections = editor.selections; 198 const selections = editor.selections;
194 const textDocument = { uri: editor.document.uri.toString() }; 199 const textDocument = ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document);
195 200
196 const options: vscode.InputBoxOptions = { 201 const options: vscode.InputBoxOptions = {
197 value: "() ==>> ()", 202 value: "() ==>> ()",
@@ -339,7 +344,7 @@ export function expandMacro(ctx: Ctx): Cmd {
339 const position = editor.selection.active; 344 const position = editor.selection.active;
340 345
341 const expanded = await client.sendRequest(ra.expandMacro, { 346 const expanded = await client.sendRequest(ra.expandMacro, {
342 textDocument: { uri: editor.document.uri.toString() }, 347 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
343 position, 348 position,
344 }); 349 });
345 350
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index d167041c4..f286b68a6 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -4,7 +4,10 @@
4 4
5import * as lc from "vscode-languageclient"; 5import * as lc from "vscode-languageclient";
6 6
7export const analyzerStatus = new lc.RequestType0<string, void>("rust-analyzer/analyzerStatus"); 7export interface AnalyzerStatusParams {
8 textDocument?: lc.TextDocumentIdentifier;
9}
10export const analyzerStatus = new lc.RequestType<AnalyzerStatusParams, string, void>("rust-analyzer/analyzerStatus");
8export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage"); 11export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage");
9 12
10export type Status = "loading" | "ready" | "invalid" | "needsReload"; 13export type Status = "loading" | "ready" | "invalid" | "needsReload";
@@ -66,8 +69,10 @@ export interface Runnable {
66 args: { 69 args: {
67 workspaceRoot?: string; 70 workspaceRoot?: string;
68 cargoArgs: string[]; 71 cargoArgs: string[];
72 cargoExtraArgs: string[];
69 executableArgs: string[]; 73 executableArgs: string[];
70 expectTest?: boolean; 74 expectTest?: boolean;
75 overrideCargo?: string;
71 }; 76 };
72} 77}
73export 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}