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

Commit b1bd3c4

Browse files
committed
Allow rustupless rls usage
1 parent 4584894 commit b1bd3c4

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

lib/index.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ async function rustupDefaultToolchain() {
8787
return stdout.split("-")[0].trim()
8888
}
8989

90+
async function hasCommand(rustCommand) {
91+
try {
92+
await exec(`${rustCommand} -V`)
93+
return true
94+
} catch (e) {
95+
return false
96+
}
97+
}
98+
9099
/** @return {?string} developer override of the command to start a Rls instance */
91100
function rlsCommandOverride() {
92101
return atom.config.get('ide-rust.rlsCommandOverride')
@@ -242,6 +251,14 @@ async function checkRls(busySignalService, cwd) {
242251
const toolchainArg = toolchain && `--toolchain ${toolchain}` || ""
243252

244253
_checkingRls = (async () => {
254+
if (!await hasCommand("rustup")) {
255+
if (await hasCommand("rls")) {
256+
return // have system rls without rustup
257+
} else {
258+
throw new Error("rls & rustup missing")
259+
}
260+
}
261+
245262
let { stdout: toolchainList } = await exec(`rustup component list ${toolchainArg}`, { cwd })
246263
if (
247264
toolchainList.search(/^rls.* \((default|installed)\)$/m) >= 0 &&
@@ -280,14 +297,14 @@ class RustLanguageClient extends AutoLanguageClient {
280297
this.config = {
281298
rlsToolchain: {
282299
description: 'Sets the toolchain installed using rustup and used to run the Rls.' +
283-
' When blank will use the rustup or system default.' +
300+
' When blank will use the rustup/system default.' +
284301
' For example ***nightly***, ***stable***, ***beta***, or ***nightly-yyyy-mm-dd***.',
285302
type: 'string',
286303
default: '',
287304
order: 1
288305
},
289306
checkForToolchainUpdates: {
290-
description: 'Check on startup & periodically for toolchain updates, prompting to install if available',
307+
description: 'Check on startup & periodically for rustup toolchain updates, prompting to install if available.',
291308
type: 'boolean',
292309
default: true,
293310
order: 2
@@ -336,6 +353,12 @@ class RustLanguageClient extends AutoLanguageClient {
336353
async _promptToUpdateToolchain() {
337354
if (!atom.config.get('ide-rust.checkForToolchainUpdates')) return
338355

356+
if (!await hasCommand("rustup")) {
357+
atom.config.set('ide-rust.checkForToolchainUpdates', false)
358+
this._handleMissingRustup()
359+
return
360+
}
361+
339362
const confToolchain = configToolchain() || await rustupDefaultToolchain()
340363
if (!confToolchain) return
341364

@@ -635,7 +658,7 @@ class RustLanguageClient extends AutoLanguageClient {
635658
return
636659
}
637660

638-
if (!this._periodicUpdateChecking) {
661+
if (!this._periodicUpdateChecking && await hasCommand("rustup")) {
639662
// if haven't started periodic checks for updates yet start now
640663
let periodicUpdateTimeoutId
641664
const periodicUpdate = async () => {
@@ -657,9 +680,7 @@ class RustLanguageClient extends AutoLanguageClient {
657680

658681
let cmdOverride = rlsCommandOverride()
659682
if (cmdOverride) {
660-
if (!this._warnedAboutRlsCommandOverride && cmdOverride !== 'rls') {
661-
// Don't warn if literally 'rls' as this is a workaround for no-rustup environments
662-
// TODO: Remove !== 'rls' check once better no-rustup support is in
683+
if (!this._warnedAboutRlsCommandOverride) {
663684
clearIdeRustInfos()
664685
atom.notifications.addInfo(`Using rls command \`${cmdOverride}\``)
665686
this._warnedAboutRlsCommandOverride = true

0 commit comments

Comments
 (0)