"Use [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)"
]
},
- "rust-analyzer.debug.sourceFileMap": {
- "type": "object",
+ "rust-analyzer.debug.sourceFileMap": {
+ "type": ["object", "string"],
+ "const": "auto",
"description": "Optional source file mappings passed to the debug engine.",
"default": {
"/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"
}
get debug() {
- // "/rustc/<id>" used by suggestions only.
- const { ["/rustc/<id>"]: _, ...sourceFileMap } = this.get<Record<string, string>>("debug.sourceFileMap");
+ let sourceFileMap = this.get<Record<string, string> | "auto">("debug.sourceFileMap");
+ if (sourceFileMap !== "auto") {
+ // "/rustc/<id>" used by suggestions only.
+ const { ["/rustc/<id>"]: _, ...trimmed } = this.get<Record<string, string>>("debug.sourceFileMap");
+ sourceFileMap = trimmed;
+ }
return {
engine: this.get<string>("debug.engine"),
import * as path from 'path';
import * as ra from './lsp_ext';
-import { Cargo, sysrootForDir as getSysroot } from './toolchain';
+import { Cargo, getSysroot } from './toolchain';
import { Ctx } from "./ctx";
import { prepareEnv } from "./run";
const executable = await getDebugExecutable(runnable);
const env = prepareEnv(runnable, ctx.config.runnableEnv);
let sourceFileMap = debugOptions.sourceFileMap;
- if ( !sourceFileMap || Object.keys(sourceFileMap).length === 0 ) {
+ if (sourceFileMap === "auto") {
// let's try to use the default toolchain
const sysroot = await getSysroot(wsFolder);
- const rustlib_src = path.normalize(sysroot + "/lib/rustlib/src/rust");
- sourceFileMap = { "/rustc/*": rustlib_src };
+ const rustlib = path.normalize(sysroot + "/lib/rustlib/src/rust");
+ sourceFileMap = { "/rustc/*": rustlib };
}
const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), env, sourceFileMap);
import * as fs from 'fs';
import * as readline from 'readline';
import { OutputChannel } from 'vscode';
-import { log, memoize } from './util';
+import { execute, log, memoize } from './util';
interface CompilationArtifact {
fileName: string;
}
/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
-export function sysrootForDir(dir: string): Promise<string> {
- const rustc_path = getPathForExecutable("rustc");
-
- return new Promise((resolve, reject) => {
- cp.exec(`${rustc_path} --print sysroot`, { cwd: dir }, (err, stdout, stderr) => {
- if (err) {
- reject(err);
- return;
- }
-
- if (stderr) {
- reject(new Error(stderr));
- return;
- }
+export function getSysroot(dir: string): Promise<string> {
+ const rustcPath = getPathForExecutable("rustc");
- resolve(stdout.trimEnd());
- });
- });
+ // do not memoize the result because the toolchain may change between runs
+ return execute(`${rustcPath} --print sysroot`, { cwd: dir });
}
/** Mirrors `toolchain::cargo()` implementation */
import * as lc from "vscode-languageclient/node";
import * as vscode from "vscode";
import { strict as nativeAssert } from "assert";
-import { spawnSync } from "child_process";
+import { exec, ExecOptions, spawnSync } from "child_process";
import { inspect } from "util";
export function assert(condition: boolean, explanation: string): asserts condition {
return result;
};
}
+
+/** Awaitable wrapper around `child_process.exec` */
+export function execute(command: string, options: ExecOptions): Promise<string> {
+ return new Promise((resolve, reject) => {
+ exec(command, options, (err, stdout, stderr) => {
+ if (err) {
+ reject(err);
+ return;
+ }
+
+ if (stderr) {
+ reject(new Error(stderr));
+ return;
+ }
+
+ resolve(stdout.trimEnd());
+ });
+ });
+}
\ No newline at end of file