aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/config.ts8
-rw-r--r--editors/code/src/debug.ts8
-rw-r--r--editors/code/src/toolchain.ts23
-rw-r--r--editors/code/src/util.ts21
5 files changed, 38 insertions, 27 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index fa5632f90..5437a0648 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -353,8 +353,9 @@
353 "Use [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)" 353 "Use [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)"
354 ] 354 ]
355 }, 355 },
356 "rust-analyzer.debug.sourceFileMap": { 356 "rust-analyzer.debug.sourceFileMap": {
357 "type": "object", 357 "type": ["object", "string"],
358 "const": "auto",
358 "description": "Optional source file mappings passed to the debug engine.", 359 "description": "Optional source file mappings passed to the debug engine.",
359 "default": { 360 "default": {
360 "/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust" 361 "/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 82f0a0566..603ff930d 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -134,8 +134,12 @@ export class Config {
134 } 134 }
135 135
136 get debug() { 136 get debug() {
137 // "/rustc/<id>" used by suggestions only. 137 let sourceFileMap = this.get<Record<string, string> | "auto">("debug.sourceFileMap");
138 const { ["/rustc/<id>"]: _, ...sourceFileMap } = this.get<Record<string, string>>("debug.sourceFileMap"); 138 if (sourceFileMap !== "auto") {
139 // "/rustc/<id>" used by suggestions only.
140 const { ["/rustc/<id>"]: _, ...trimmed } = this.get<Record<string, string>>("debug.sourceFileMap");
141 sourceFileMap = trimmed;
142 }
139 143
140 return { 144 return {
141 engine: this.get<string>("debug.engine"), 145 engine: this.get<string>("debug.engine"),
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index fe8ec1be4..8c6969dc6 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -3,7 +3,7 @@ import * as vscode from 'vscode';
3import * as path from 'path'; 3import * as path from 'path';
4import * as ra from './lsp_ext'; 4import * as ra from './lsp_ext';
5 5
6import { Cargo, sysrootForDir as getSysroot } from './toolchain'; 6import { Cargo, getSysroot } from './toolchain';
7import { Ctx } from "./ctx"; 7import { Ctx } from "./ctx";
8import { prepareEnv } from "./run"; 8import { prepareEnv } from "./run";
9 9
@@ -105,11 +105,11 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<v
105 const executable = await getDebugExecutable(runnable); 105 const executable = await getDebugExecutable(runnable);
106 const env = prepareEnv(runnable, ctx.config.runnableEnv); 106 const env = prepareEnv(runnable, ctx.config.runnableEnv);
107 let sourceFileMap = debugOptions.sourceFileMap; 107 let sourceFileMap = debugOptions.sourceFileMap;
108 if ( !sourceFileMap || Object.keys(sourceFileMap).length === 0 ) { 108 if (sourceFileMap === "auto") {
109 // let's try to use the default toolchain 109 // let's try to use the default toolchain
110 const sysroot = await getSysroot(wsFolder); 110 const sysroot = await getSysroot(wsFolder);
111 const rustlib_src = path.normalize(sysroot + "/lib/rustlib/src/rust"); 111 const rustlib = path.normalize(sysroot + "/lib/rustlib/src/rust");
112 sourceFileMap = { "/rustc/*": rustlib_src }; 112 sourceFileMap = { "/rustc/*": rustlib };
113 } 113 }
114 114
115 const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), env, sourceFileMap); 115 const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), env, sourceFileMap);
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index b746da1d9..5725bcafe 100644
--- a/editors/code/src/toolchain.ts
+++ b/editors/code/src/toolchain.ts
@@ -4,7 +4,7 @@ import * as path from 'path';
4import * as fs from 'fs'; 4import * as fs from 'fs';
5import * as readline from 'readline'; 5import * as readline from 'readline';
6import { OutputChannel } from 'vscode'; 6import { OutputChannel } from 'vscode';
7import { log, memoize } from './util'; 7import { execute, log, memoize } from './util';
8 8
9interface CompilationArtifact { 9interface CompilationArtifact {
10 fileName: string; 10 fileName: string;
@@ -122,24 +122,11 @@ export class Cargo {
122} 122}
123 123
124/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/ 124/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
125export function sysrootForDir(dir: string): Promise<string> { 125export function getSysroot(dir: string): Promise<string> {
126 const rustc_path = getPathForExecutable("rustc"); 126 const rustcPath = getPathForExecutable("rustc");
127
128 return new Promise((resolve, reject) => {
129 cp.exec(`${rustc_path} --print sysroot`, { cwd: dir }, (err, stdout, stderr) => {
130 if (err) {
131 reject(err);
132 return;
133 }
134
135 if (stderr) {
136 reject(new Error(stderr));
137 return;
138 }
139 127
140 resolve(stdout.trimEnd()); 128 // do not memoize the result because the toolchain may change between runs
141 }); 129 return execute(`${rustcPath} --print sysroot`, { cwd: dir });
142 });
143} 130}
144 131
145/** Mirrors `toolchain::cargo()` implementation */ 132/** Mirrors `toolchain::cargo()` implementation */
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts
index 53492a445..fc5c9e94e 100644
--- a/editors/code/src/util.ts
+++ b/editors/code/src/util.ts
@@ -1,7 +1,7 @@
1import * as lc from "vscode-languageclient/node"; 1import * as lc from "vscode-languageclient/node";
2import * as vscode from "vscode"; 2import * as vscode from "vscode";
3import { strict as nativeAssert } from "assert"; 3import { strict as nativeAssert } from "assert";
4import { spawnSync } from "child_process"; 4import { exec, ExecOptions, spawnSync } from "child_process";
5import { inspect } from "util"; 5import { inspect } from "util";
6 6
7export function assert(condition: boolean, explanation: string): asserts condition { 7export function assert(condition: boolean, explanation: string): asserts condition {
@@ -141,3 +141,22 @@ export function memoize<Ret, TThis, Param extends string>(func: (this: TThis, ar
141 return result; 141 return result;
142 }; 142 };
143} 143}
144
145/** Awaitable wrapper around `child_process.exec` */
146export function execute(command: string, options: ExecOptions): Promise<string> {
147 return new Promise((resolve, reject) => {
148 exec(command, options, (err, stdout, stderr) => {
149 if (err) {
150 reject(err);
151 return;
152 }
153
154 if (stderr) {
155 reject(new Error(stderr));
156 return;
157 }
158
159 resolve(stdout.trimEnd());
160 });
161 });
162} \ No newline at end of file