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

Commit bfb8328

Browse files
authored
Improve rls console logging (#48)
* Add rls env: RUST_BACKTRACE=1 * Add rls env: RUST_LOG=atom_process.env.RUST_LOG * When core.debugLSP add rls env: RUST_LOG=rls=warn (if not already set) * Avoid concurrent checkRls promises _(can cause update error messages)_ * Don't use parent process RUST_SRC_PATH, it's unlikely to be correct for a dated toolchain
1 parent 789f946 commit bfb8328

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

lib/index.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,30 @@ function rustcSysroot(toolchain) {
104104
* @return {object} environment vars
105105
*/
106106
function serverEnv(toolchain) {
107-
const env = { PATH: getPath() }
107+
const env = {
108+
PATH: getPath(),
109+
RUST_BACKTRACE: '1',
110+
RUST_LOG: process.env.RUST_LOG,
111+
}
112+
113+
if (!env.RUST_LOG && atom.config.get('core.debugLSP')) {
114+
env.RUST_LOG = 'rls=warn'
115+
}
108116

109117
if (toolchain) {
110-
let rustSrcPath = process.env.RUST_SRC_PATH
111-
if (!rustSrcPath) {
112-
try {
113-
rustSrcPath = path.join(rustcSysroot(toolchain), "/lib/rustlib/src/rust/src/")
114-
}
115-
catch (e) {
116-
console.error("Failed to find sysroot", e)
117-
return env
118-
}
118+
try {
119+
env.RUST_SRC_PATH = path.join(rustcSysroot(toolchain), "/lib/rustlib/src/rust/src/")
120+
}
121+
catch (e) {
122+
console.error("Failed to find sysroot", e)
119123
}
120-
env.RUST_SRC_PATH = rustSrcPath
121124
}
122-
123125
return env
124126
}
125127

128+
// ongoing promise
129+
let _checkingRls
130+
126131
/**
127132
* Check for and install Rls
128133
* @param {BusySignalService} [busySignalService]
@@ -131,7 +136,9 @@ function serverEnv(toolchain) {
131136
function checkRls(busySignalService) {
132137
let toolchain = configToolchain()
133138

134-
return exec(`rustup component list --toolchain ${toolchain}`).then(results => {
139+
if (_checkingRls) return _checkingRls
140+
141+
_checkingRls = exec(`rustup component list --toolchain ${toolchain}`).then(results => {
135142
const { stdout } = results
136143
if (
137144
stdout.search(/^rls-preview.* \((default|installed)\)$/m) >= 0 &&
@@ -197,6 +204,14 @@ function checkRls(busySignalService) {
197204

198205
return installRlsPromise
199206
})
207+
208+
try {
209+
return _checkingRls
210+
}
211+
finally {
212+
let clearOngoing = () => _checkingRls = null
213+
_checkingRls.then(clearOngoing).catch(clearOngoing)
214+
}
200215
}
201216

202217
class RustLanguageClient extends AutoLanguageClient {

0 commit comments

Comments
 (0)