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

Commit 322d3f4

Browse files
committed
Refactor _promptToUpdateToolchain async/await
1 parent e88bfed commit 322d3f4

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

lib/index.js

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -247,47 +247,43 @@ class RustLanguageClient extends AutoLanguageClient {
247247
}
248248

249249
// check for toolchain updates if installed & not dated
250-
_promptToUpdateToolchain() {
250+
async _promptToUpdateToolchain() {
251251
if (!atom.config.get('ide-rust.checkForToolchainUpdates')) return
252252

253253
const confToolchain = configToolchain()
254254
const dated = confToolchain.match(DATED_REGEX)
255255
const toolchain = (dated ? dated[1] : confToolchain)
256256

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

293289
/**

0 commit comments

Comments
 (0)