about summary refs log tree commit diff
path: root/editors/code/src/util.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-27 20:41:35 +0000
committerGitHub <noreply@github.com>2021-04-27 20:41:35 +0000
commitfb45d2adeccfc6732b702cd8fa2911b385bc15b7 (patch)
tree41ab22e69528ccb346bc01b913f9251a24925960 /editors/code/src/util.ts
parente2b87735cc4b54ca530e7a99070da585d480b1c3 (diff)
parent1b4197cb3520e4a71f118aac61a83bab1a6f5931 (diff)
downloadrust-fb45d2adeccfc6732b702cd8fa2911b385bc15b7.tar.gz
rust-fb45d2adeccfc6732b702cd8fa2911b385bc15b7.zip
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 <vit@conrlab.com>
Diffstat (limited to 'editors/code/src/util.ts')
-rw-r--r--editors/code/src/util.ts21
1 files changed, 20 insertions, 1 deletions
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts
index 53492a445c4..56e0e439e98 100644
--- a/editors/code/src/util.ts
+++ b/editors/code/src/util.ts
@@ -1,7 +1,7 @@
 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 {
@@ -141,3 +141,22 @@ export function memoize<Ret, TThis, Param extends string>(func: (this: TThis, ar
         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());
+        });
+    });
+}