aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/toolchain.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-27 21:41:35 +0100
committerGitHub <[email protected]>2021-04-27 21:41:35 +0100
commitfb45d2adeccfc6732b702cd8fa2911b385bc15b7 (patch)
tree41ab22e69528ccb346bc01b913f9251a24925960 /editors/code/src/toolchain.ts
parente2b87735cc4b54ca530e7a99070da585d480b1c3 (diff)
parent1b4197cb3520e4a71f118aac61a83bab1a6f5931 (diff)
Merge #8624
8624: Automatically detect rust library source file map r=vsrs a=vsrs This PR adds a new possible `rust-analyzer.debug.sourceFileMap` value: ```json { "rust-analyzer.debug.sourceFileMap": "auto" } ``` I did not make it the default because it uses two shell calls (`rustc --print sysroot` and `rustc -V -v`). First one can be slow (https://github.com/rust-lang/rustup/issues/783) Fixes #8619 Co-authored-by: vsrs <[email protected]>
Diffstat (limited to 'editors/code/src/toolchain.ts')
-rw-r--r--editors/code/src/toolchain.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index a5dc3cf0c..68826c478 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;
@@ -121,6 +121,24 @@ export class Cargo {
121 } 121 }
122} 122}
123 123
124/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
125export function getSysroot(dir: string): Promise<string> {
126 const rustcPath = getPathForExecutable("rustc");
127
128 // do not memoize the result because the toolchain may change between runs
129 return execute(`${rustcPath} --print sysroot`, { cwd: dir });
130}
131
132export async function getRustcId(dir: string): Promise<string> {
133 const rustcPath = getPathForExecutable("rustc");
134
135 // do not memoize the result because the toolchain may change between runs
136 const data = await execute(`${rustcPath} -V -v`, { cwd: dir });
137 const rx = /commit-hash:\s(.*)$/m.compile();
138
139 return rx.exec(data)![1];
140}
141
124/** Mirrors `toolchain::cargo()` implementation */ 142/** Mirrors `toolchain::cargo()` implementation */
125export function cargoPath(): string { 143export function cargoPath(): string {
126 return getPathForExecutable("cargo"); 144 return getPathForExecutable("cargo");