Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit e88bfed

Browse files
committed
Refactor serverEnv, rustcSysroot async/await
1 parent c07a7c3 commit e88bfed

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,18 @@ function installCompiler() {
9191

9292
/**
9393
* @param {string} toolchain
94-
* @return {string} `rustc --print sysroot` stdout
94+
* @return {Promise<string>} `rustc --print sysroot` stdout
9595
*/
96-
function rustcSysroot(toolchain) {
97-
return cp.execSync(`rustup run ${toolchain} rustc --print sysroot`, {
98-
env: { PATH: getPath() }
99-
}).toString().trim()
96+
async function rustcSysroot(toolchain) {
97+
let { stdout } = await exec(`rustup run ${toolchain} rustc --print sysroot`)
98+
return stdout.trim()
10099
}
101100

102101
/**
103102
* @param {string} [toolchain]
104-
* @return {object} environment vars
103+
* @return {Promise<object>} environment vars
105104
*/
106-
function serverEnv(toolchain) {
105+
async function serverEnv(toolchain) {
107106
const env = {
108107
PATH: getPath(),
109108
RUST_BACKTRACE: '1',
@@ -116,7 +115,8 @@ function serverEnv(toolchain) {
116115

117116
if (toolchain) {
118117
try {
119-
env.RUST_SRC_PATH = path.join(rustcSysroot(toolchain), "/lib/rustlib/src/rust/src/")
118+
let sysroot = await rustcSysroot(toolchain)
119+
env.RUST_SRC_PATH = path.join(sysroot, "/lib/rustlib/src/rust/src/")
120120
}
121121
catch (e) {
122122
console.error("Failed to find sysroot: " + e)
@@ -511,7 +511,7 @@ class RustLanguageClient extends AutoLanguageClient {
511511
this._warnedAboutRlsCommandOverride = true
512512
}
513513
return cp.spawn(cmdOverride, {
514-
env: serverEnv(configToolchain()),
514+
env: await serverEnv(configToolchain()),
515515
shell: true,
516516
cwd: projectPath
517517
})
@@ -522,7 +522,7 @@ class RustLanguageClient extends AutoLanguageClient {
522522
await checkRls(this.busySignalService)
523523
let toolchain = configToolchain()
524524
return cp.spawn("rustup", ["run", toolchain, "rls"], {
525-
env: serverEnv(toolchain),
525+
env: await serverEnv(toolchain),
526526
cwd: projectPath
527527
})
528528
}

0 commit comments

Comments
 (0)