@@ -32,8 +32,7 @@ async function exec(command, { cwd }={}) {
32
32
}
33
33
34
34
function logErr ( e , logFn = console . warn ) {
35
- const message = e && '' + e
36
- message && logFn ( message )
35
+ e && logFn ( '' + e )
37
36
}
38
37
39
38
function clearIdeRustInfos ( ) {
@@ -96,6 +95,19 @@ async function hasCommand(rustCommand) {
96
95
}
97
96
}
98
97
98
+ async function rustupOverrides ( ) {
99
+ let { stdout } = await exec ( "rustup override list" )
100
+ return stdout . split ( / [ \r \n ] + / g)
101
+ . map ( line => {
102
+ let lastSpace = line . lastIndexOf ( ' ' )
103
+ return {
104
+ path : line . slice ( 0 , lastSpace ) . trim ( ) ,
105
+ toolchain : line . slice ( lastSpace ) . trim ( )
106
+ }
107
+ } )
108
+ . filter ( ( { path, toolchain } ) => path && toolchain )
109
+ }
110
+
99
111
/** @return {?string } developer override of the command to start a Rls instance */
100
112
function rlsCommandOverride ( ) {
101
113
return atom . config . get ( 'ide-rust.rlsCommandOverride' )
@@ -291,6 +303,7 @@ class RustLanguageClient extends AutoLanguageClient {
291
303
super ( )
292
304
/** (projectPath -> RlsProject) mappings */
293
305
this . projects = { }
306
+ this . activeOverrides = new Set ( )
294
307
this . disposables = new CompositeDisposable ( )
295
308
296
309
/** Configuration schema */
@@ -343,14 +356,31 @@ class RustLanguageClient extends AutoLanguageClient {
343
356
}
344
357
}
345
358
359
+ async _refreshActiveOverrides ( ) {
360
+ try {
361
+ const overrides = ( await rustupOverrides ( ) )
362
+ . filter ( ( { path } ) => Object . keys ( this . projects ) . some ( project => project . startsWith ( path ) ) )
363
+ . map ( override => override . toolchain )
364
+ const oldActive = this . activeOverrides
365
+ this . activeOverrides = new Set ( overrides )
366
+ if ( this . activeOverrides . size > oldActive . size ) {
367
+ const confToolchain = configToolchain ( ) || await rustupDefaultToolchain ( )
368
+ if ( confToolchain ) oldActive . add ( confToolchain )
369
+ this . _promptToUpdateToolchain ( { ignore : oldActive } )
370
+ }
371
+ } catch ( e ) {
372
+ if ( await hasCommand ( "rustup" ) ) logErr ( e )
373
+ }
374
+ }
375
+
346
376
/** @param {?string } reason Reason for the restart shown in the notification */
347
377
async _restartLanguageServers ( reason ) {
348
378
await this . restartAllServers ( )
349
379
if ( reason ) atom . notifications . addSuccess ( reason , { _src : 'ide-rust' } )
350
380
}
351
381
352
382
// check for toolchain updates if installed & not dated
353
- async _promptToUpdateToolchain ( ) {
383
+ async _promptToUpdateToolchain ( { ignore } = { } ) {
354
384
if ( ! atom . config . get ( 'ide-rust.checkForToolchainUpdates' ) ) return
355
385
356
386
if ( ! await hasCommand ( "rustup" ) ) {
@@ -359,49 +389,58 @@ class RustLanguageClient extends AutoLanguageClient {
359
389
return
360
390
}
361
391
362
- const confToolchain = configToolchain ( ) || await rustupDefaultToolchain ( )
363
- if ( ! confToolchain ) return
392
+ const toolchains = new Set ( this . activeOverrides )
364
393
365
- const dated = confToolchain . match ( DATED_REGEX )
366
- const toolchain = ( dated ? dated [ 1 ] : confToolchain )
367
- const switching = confToolchain !== toolchain
394
+ const confToolchain = configToolchain ( ) || await rustupDefaultToolchain ( )
395
+ if ( confToolchain ) toolchains . add ( confToolchain )
396
+
397
+ Array . from ( toolchains )
398
+ . filter ( toolchain => ! ignore || ! ignore . has ( toolchain ) )
399
+ . forEach ( async confToolchain => {
400
+ const dated = confToolchain . match ( DATED_REGEX )
401
+ let toolchain = ( dated ? dated [ 1 ] : confToolchain )
402
+ if ( ! dated && toolchain . includes ( '-' ) ) {
403
+ toolchain = toolchain . split ( '-' ) [ 0 ]
404
+ }
368
405
369
- let { stdout : currentVersion } = await rustupRun ( confToolchain , "rustc --version" )
370
- let newVersion = await fetchLatestDist ( { toolchain, currentVersion } ) . catch ( ( ) => false )
371
- if ( ! newVersion ) return
406
+ let { stdout : currentVersion } = await rustupRun ( confToolchain , "rustc --version" )
407
+ let newVersion = await fetchLatestDist ( { toolchain, currentVersion } ) . catch ( ( ) => false )
408
+ if ( ! newVersion ) return
372
409
373
- atom . notifications . addInfo ( `Rls \`${ toolchain } \` toolchain update available` , {
374
- description : newVersion ,
375
- _src : 'ide-rust' ,
376
- dismissable : true ,
377
- buttons : [ {
378
- text : switching ? 'Update & Switch' : 'Update' ,
379
- onDidClick : ( ) => {
380
- clearIdeRustInfos ( )
381
-
382
- const updatePromise = exec ( `rustup update ${ toolchain } ` )
383
- // set config in case going from dated -> latest
384
- . then ( ( ) => switching && atom . config . set ( 'ide-rust.rlsToolchain' , toolchain ) )
385
- . then ( ( ) => this . _checkToolchain ( ) )
386
- . then ( ( ) => checkRls ( ) )
387
- . then ( ( ) => this . _restartLanguageServers ( `Updated Rls toolchain` ) )
388
- . catch ( e => {
389
- logErr ( e )
390
- e && atom . notifications . addError ( `\`rustup update ${ toolchain } \` failed` , {
391
- detail : e ,
392
- dismissable : true ,
410
+ atom . notifications . addInfo ( `Rls \`${ toolchain } \` toolchain update available` , {
411
+ description : newVersion ,
412
+ _src : 'ide-rust' ,
413
+ dismissable : true ,
414
+ buttons : [ {
415
+ text : dated ? 'Update & Switch' : 'Update' ,
416
+ onDidClick : ( ) => {
417
+ clearIdeRustInfos ( )
418
+
419
+ const updatePromise = exec ( `rustup update ${ toolchain } ` )
420
+ // set config in case going from dated -> latest
421
+ . then ( ( ) => dated && atom . config . set ( 'ide-rust.rlsToolchain' , toolchain ) )
422
+ . then ( ( ) => this . _checkToolchain ( ) )
423
+ . then ( ( ) => checkRls ( ) )
424
+ . then ( ( ) => this . _restartLanguageServers ( `Updated Rls toolchain` ) )
425
+ . catch ( e => {
426
+ logErr ( e )
427
+ e && atom . notifications . addError ( `\`rustup update ${ toolchain } \` failed` , {
428
+ detail : e ,
429
+ dismissable : true ,
430
+ } )
393
431
} )
394
- } )
395
432
396
- if ( this . busySignalService ) {
397
- this . busySignalService . reportBusyWhile (
398
- `Updating rust \`${ toolchain } \` toolchain` ,
399
- ( ) => updatePromise
400
- )
401
- }
402
- }
403
- } ]
404
- } )
433
+ if ( this . busySignalService ) {
434
+ this . busySignalService . reportBusyWhile (
435
+ `Updating rust \`${ toolchain } \` toolchain` ,
436
+ ( ) => updatePromise
437
+ )
438
+ }
439
+ }
440
+ } ]
441
+ } )
442
+ } )
443
+
405
444
}
406
445
407
446
/**
@@ -620,9 +659,12 @@ class RustLanguageClient extends AutoLanguageClient {
620
659
621
660
server . process . on ( 'exit' , ( ) => {
622
661
delete this . projects [ server . projectPath ]
662
+ this . _refreshActiveOverrides ( )
623
663
} )
624
664
625
665
project . sendRlsTomlConfig ( )
666
+
667
+ this . _refreshActiveOverrides ( )
626
668
}
627
669
628
670
getGrammarScopes ( ) {
0 commit comments