Autodetect rust library source file map

This commit is contained in:
vsrs 2021-04-22 15:27:56 +03:00
parent d1c9bd134d
commit 8f781e782c
2 changed files with 31 additions and 2 deletions

View file

@ -121,6 +121,27 @@ export class Cargo {
}
}
/** 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;
}
resolve(stdout.trimEnd());
});
});
}
/** Mirrors `toolchain::cargo()` implementation */
export function cargoPath(): string {
return getPathForExecutable("cargo");