@@ -23,7 +23,7 @@ function getPath() {
23
23
return PATH
24
24
}
25
25
26
- function exec ( command ) {
26
+ async function exec ( command ) {
27
27
return new Promise ( ( resolve , reject ) => {
28
28
cp . exec ( command , { env : { PATH : getPath ( ) } } , ( err , stdout , stderr ) => {
29
29
if ( err != null ) {
@@ -237,54 +237,53 @@ class RustLanguageClient extends AutoLanguageClient {
237
237
}
238
238
}
239
239
240
- /** @param {string } reason Reason for the restart shown in the notification */
240
+ /** @param {? string } reason Reason for the restart shown in the notification */
241
241
_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' } ) )
243
243
}
244
244
245
245
// check for toolchain updates if installed & not dated
246
246
_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
266
248
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
+ )
281
280
}
282
- } ]
283
- } )
284
- }
285
- } )
286
- . catch ( e => console . error ( e ) )
287
- }
281
+ }
282
+ } ]
283
+ } )
284
+ }
285
+ } )
286
+ . catch ( e => console . error ( e ) )
288
287
}
289
288
290
289
/**
@@ -439,6 +438,12 @@ class RustLanguageClient extends AutoLanguageClient {
439
438
clearTimeout ( periodicUpdateTimeoutId )
440
439
} ) )
441
440
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
+ ) )
442
447
}
443
448
444
449
deactivate ( ) {
0 commit comments