From 8f781e782c7e16aa323672620753ec31526d2b90 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 22 Apr 2021 15:27:56 +0300 Subject: Autodetect rust library source file map --- editors/code/src/toolchain.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'editors/code/src/toolchain.ts') diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts index a5dc3cf0c..b746da1d9 100644 --- a/editors/code/src/toolchain.ts +++ b/editors/code/src/toolchain.ts @@ -121,6 +121,27 @@ export class Cargo { } } +/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/ +export function sysrootForDir(dir: string): Promise { + 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"); -- cgit v1.2.3