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

Commit c5ca2bf

Browse files
committed
Add command: restart-all-language-servers
1 parent cef1088 commit c5ca2bf

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Or you can install from Settings view by searching for `ide-rust`.
3030

3131
No other packages or manual setup is required as these will be handled with user prompts after install.
3232

33+
## Commands
34+
- `ide-rust:restart-all-language-servers` Restart all currently active Rls processes
35+
3336
## Multi-crate projects
3437
A root `Cargo.toml` is required in each atom project, however cargo workspaces can be used to support multiple crates in a single project.
3538
For example, a project with *'rust_foo'* & *'rust_bar'* directories/crates could have the following root `Cargo.toml`

lib/index.js

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function getPath() {
2323
return PATH
2424
}
2525

26-
function exec(command) {
26+
async function exec(command) {
2727
return new Promise((resolve, reject) => {
2828
cp.exec(command, { env: { PATH: getPath() } }, (err, stdout, stderr) => {
2929
if (err != null) {
@@ -237,54 +237,53 @@ class RustLanguageClient extends AutoLanguageClient {
237237
}
238238
}
239239

240-
/** @param {string} reason Reason for the restart shown in the notification */
240+
/** @param {?string} reason Reason for the restart shown in the notification */
241241
_restartLanguageServers(reason) {
242-
this.restartAllServers().then(() => atom.notifications.addSuccess(reason, { _src: 'ide-rust' }))
242+
this.restartAllServers().then(() => reason && atom.notifications.addSuccess(reason, { _src: 'ide-rust' }))
243243
}
244244

245245
// check for toolchain updates if installed & not dated
246246
_promptToUpdateToolchain() {
247-
const confToolchain = configToolchain()
248-
249-
if (atom.config.get('ide-rust.checkForToolchainUpdates')) {
250-
const dated = confToolchain.match(DATED_REGEX)
251-
const toolchain = (dated ? dated[1] : confToolchain)
252-
253-
exec(`rustup run ${confToolchain} rustc --version`)
254-
.then(({ stdout }) => fetchLatestDist({ toolchain, currentVersion: stdout }))
255-
.catch(() => false)
256-
.then(newVersion => {
257-
if (newVersion) {
258-
atom.notifications.addInfo(`Rls \`${toolchain}\` toolchain update available`, {
259-
description: newVersion,
260-
_src: 'ide-rust',
261-
dismissable: true,
262-
buttons: [{
263-
text: confToolchain === toolchain ? 'Update' : 'Update & Switch',
264-
onDidClick: () => {
265-
clearIdeRustInfos()
247+
if (!atom.config.get('ide-rust.checkForToolchainUpdates')) return
266248

267-
const updatePromise = exec(`rustup update ${toolchain}`)
268-
// set config in case going from dated -> latest
269-
.then(() => atom.config.set('ide-rust.rlsToolchain', toolchain))
270-
.then(() => this._checkToolchain())
271-
.then(() => checkRls())
272-
.then(() => this._restartLanguageServers(`Updated Rls toolchain`))
273-
.catch(e => console.error(e))
274-
275-
if (this.busySignalService) {
276-
this.busySignalService.reportBusyWhile(
277-
`Updating rust \`${toolchain}\` toolchain`,
278-
() => updatePromise
279-
)
280-
}
249+
const confToolchain = configToolchain()
250+
const dated = confToolchain.match(DATED_REGEX)
251+
const toolchain = (dated ? dated[1] : confToolchain)
252+
253+
exec(`rustup run ${confToolchain} rustc --version`)
254+
.then(({ stdout }) => fetchLatestDist({ toolchain, currentVersion: stdout }))
255+
.catch(() => false)
256+
.then(newVersion => {
257+
if (newVersion) {
258+
atom.notifications.addInfo(`Rls \`${toolchain}\` toolchain update available`, {
259+
description: newVersion,
260+
_src: 'ide-rust',
261+
dismissable: true,
262+
buttons: [{
263+
text: confToolchain === toolchain ? 'Update' : 'Update & Switch',
264+
onDidClick: () => {
265+
clearIdeRustInfos()
266+
267+
const updatePromise = exec(`rustup update ${toolchain}`)
268+
// set config in case going from dated -> latest
269+
.then(() => atom.config.set('ide-rust.rlsToolchain', toolchain))
270+
.then(() => this._checkToolchain())
271+
.then(() => checkRls())
272+
.then(() => this._restartLanguageServers(`Updated Rls toolchain`))
273+
.catch(e => console.error(e))
274+
275+
if (this.busySignalService) {
276+
this.busySignalService.reportBusyWhile(
277+
`Updating rust \`${toolchain}\` toolchain`,
278+
() => updatePromise
279+
)
281280
}
282-
}]
283-
})
284-
}
285-
})
286-
.catch(e => console.error(e))
287-
}
281+
}
282+
}]
283+
})
284+
}
285+
})
286+
.catch(e => console.error(e))
288287
}
289288

290289
/**
@@ -439,6 +438,12 @@ class RustLanguageClient extends AutoLanguageClient {
439438
clearTimeout(periodicUpdateTimeoutId)
440439
}))
441440
periodicUpdate()
441+
442+
this.disposables.add(atom.commands.add(
443+
'atom-workspace',
444+
'ide-rust:restart-all-language-servers',
445+
() => this._restartLanguageServers('Rust language servers restarted'),
446+
))
442447
}
443448

444449
deactivate() {

0 commit comments

Comments
 (0)