@@ -27,12 +27,6 @@ export class Rustup {
27
27
*/
28
28
private pathToRustSourceCode : string | undefined ;
29
29
30
- /**
31
- * A path to the executable of RLS.
32
- * It can be undefined if the component "rls" is not installed
33
- */
34
- private pathToRlsExecutable : string | undefined ;
35
-
36
30
/**
37
31
* Components received by invoking rustup
38
32
*/
@@ -48,6 +42,10 @@ export class Rustup {
48
42
*/
49
43
private _userToolchain : Toolchain | undefined ;
50
44
45
+ /**
46
+ * The nightly toolchain chosen by the user
47
+ */
48
+ private _userNightlyToolchain : Toolchain | undefined ;
51
49
52
50
/**
53
51
* Returns the executable of Rustup
@@ -70,26 +68,6 @@ export class Rustup {
70
68
return rustup ;
71
69
}
72
70
73
- /**
74
- * Return either the only nightly toolchain or undefined if there is no nightly toolchain or
75
- * there are several nightly toolchains
76
- */
77
- public getNightlyToolchain ( logger : ChildLogger ) : Toolchain | undefined {
78
- const functionLogger = logger . createChildLogger ( 'getNightlyToolchain: ' ) ;
79
- const nightlyToolchains = this . getNightlyToolchains ( ) ;
80
- switch ( nightlyToolchains . length ) {
81
- case 0 :
82
- functionLogger . error ( 'There is no nightly toolchain' ) ;
83
- return undefined ;
84
- case 1 :
85
- functionLogger . debug ( 'There is only one nightly toolchain' ) ;
86
- return nightlyToolchains [ 0 ] ;
87
- default :
88
- functionLogger . debug ( `There are ${ nightlyToolchains . length } nightly toolchains` ) ;
89
- return undefined ;
90
- }
91
- }
92
-
93
71
/**
94
72
* Returns either the default toolchain or undefined if there are no installed toolchains
95
73
*/
@@ -109,6 +87,10 @@ export class Rustup {
109
87
return this . toolchains ;
110
88
}
111
89
90
+ public getNightlyToolchains ( ) : Toolchain [ ] {
91
+ return this . toolchains . filter ( t => t . channel === 'nightly' ) ;
92
+ }
93
+
112
94
/**
113
95
* Checks if the toolchain is installed
114
96
* @param toolchain The toolchain to check
@@ -125,10 +107,24 @@ export class Rustup {
125
107
}
126
108
127
109
/**
128
- * Returns either the path to the executable of RLS or undefined
110
+ * Returns either the nightly toolchain chosen by the user or undefined
129
111
*/
130
- public getPathToRlsExecutable ( ) : string | undefined {
131
- return this . pathToRlsExecutable ;
112
+ public getUserNightlyToolchain ( ) : Toolchain | undefined {
113
+ return this . _userNightlyToolchain ;
114
+ }
115
+
116
+ /**
117
+ * Sets the new value of the nightly toolchain in the object and in the configuration
118
+ * @param toolchain The new value
119
+ */
120
+ public setUserNightlyToolchain ( toolchain : Toolchain | undefined ) : void {
121
+ if ( this . _userNightlyToolchain === toolchain ) {
122
+ return ;
123
+ }
124
+ this . _userNightlyToolchain = toolchain ;
125
+ updateUserConfigurationParameter ( c => {
126
+ c . nightlyToolchain = toolchain ? toolchain . toString ( true , false ) : null ;
127
+ } ) ;
132
128
}
133
129
134
130
/**
@@ -143,7 +139,9 @@ export class Rustup {
143
139
return ;
144
140
}
145
141
this . _userToolchain = toolchain ;
146
- updateUserConfigurationParameter ( c => c . toolchain = toolchain ? toolchain . toString ( true , false ) : null ) ;
142
+ updateUserConfigurationParameter ( c => {
143
+ c . toolchain = toolchain ? toolchain . toString ( true , false ) : null ;
144
+ } ) ;
147
145
}
148
146
149
147
/**
@@ -188,7 +186,7 @@ export class Rustup {
188
186
*/
189
187
public async installRls ( ) : Promise < boolean > {
190
188
const logger = this . logger . createChildLogger ( 'installRls: ' ) ;
191
- const nightlyToolchain = this . getNightlyToolchain ( logger ) ;
189
+ const nightlyToolchain = this . getUserNightlyToolchain ( ) ;
192
190
if ( ! nightlyToolchain ) {
193
191
logger . error ( 'no nightly toolchain' ) ;
194
192
return false ;
@@ -197,17 +195,7 @@ export class Rustup {
197
195
nightlyToolchain ,
198
196
Rustup . getRlsComponentName ( )
199
197
) ;
200
- if ( ! isComponentInstalled ) {
201
- return false ;
202
- }
203
- // We need to update the field
204
- await this . updatePathToRlsExecutable ( ) ;
205
- if ( ! this . pathToRlsExecutable ) {
206
- logger . error ( 'RLS had been installed successfully, but we failed to find it in PATH. This should have not happened' ) ;
207
-
208
- return false ;
209
- }
210
- return true ;
198
+ return isComponentInstalled ;
211
199
}
212
200
213
201
/**
@@ -216,7 +204,7 @@ export class Rustup {
216
204
*/
217
205
public async installRustAnalysis ( ) : Promise < boolean > {
218
206
const logger = this . logger . createChildLogger ( 'installRustAnalysis: ' ) ;
219
- const nightlyToolchain = this . getNightlyToolchain ( logger ) ;
207
+ const nightlyToolchain = this . getUserNightlyToolchain ( ) ;
220
208
if ( ! nightlyToolchain ) {
221
209
logger . error ( 'no nightly toolchain' ) ;
222
210
return false ;
@@ -291,31 +279,13 @@ export class Rustup {
291
279
}
292
280
}
293
281
294
- /**
295
- * Checks if the executable of RLS is installed.
296
- * This method assigns either a path to the executable or undefined to the field `pathToRlsExecutable`, depending on if the executable is found
297
- * This method is asynchronous because it checks if the executable exists
298
- */
299
- public async updatePathToRlsExecutable ( ) : Promise < void > {
300
- const logger = this . logger . createChildLogger ( 'updatePathToRlsExecutable: ' ) ;
301
- this . pathToRlsExecutable = undefined ;
302
- const rlsPath : string | undefined = await FileSystem . findExecutablePath ( 'rls' ) ;
303
- logger . debug ( `rlsPath=${ rlsPath } ` ) ;
304
- if ( ! rlsPath ) {
305
- // RLS is installed via Rustup, but isn't found. Let a user know about it
306
- logger . error ( `Rustup had reported that RLS had been installed, but RLS wasn't found in PATH=${ process . env . PATH } ` ) ;
307
- return ;
308
- }
309
- this . pathToRlsExecutable = rlsPath ;
310
- }
311
-
312
282
/**
313
283
* Requests Rustup give a list of components, parses it, checks if RLS is present in the list and returns if it is
314
284
* @returns true if RLS can be installed otherwise false
315
285
*/
316
286
public canInstallRls ( ) : boolean {
317
287
const logger = this . logger . createChildLogger ( 'canInstallRls: ' ) ;
318
- const nightlyToolchain = this . getNightlyToolchain ( logger ) ;
288
+ const nightlyToolchain = this . getUserNightlyToolchain ( ) ;
319
289
if ( ! nightlyToolchain ) {
320
290
logger . error ( 'no nightly toolchain' ) ;
321
291
return false ;
@@ -343,7 +313,7 @@ export class Rustup {
343
313
*/
344
314
public isRlsInstalled ( ) : boolean {
345
315
const logger = this . logger . createChildLogger ( 'isRlsInstalled: ' ) ;
346
- const nightlyToolchain = this . getNightlyToolchain ( logger ) ;
316
+ const nightlyToolchain = this . getUserNightlyToolchain ( ) ;
347
317
if ( ! nightlyToolchain ) {
348
318
logger . error ( 'no nightly toolchain' ) ;
349
319
return false ;
@@ -357,7 +327,7 @@ export class Rustup {
357
327
*/
358
328
public isRustAnalysisInstalled ( ) : boolean {
359
329
const logger = this . logger . createChildLogger ( 'isRustAnalysisInstalled: ' ) ;
360
- const nightlyToolchain = this . getNightlyToolchain ( logger ) ;
330
+ const nightlyToolchain = this . getUserNightlyToolchain ( ) ;
361
331
if ( ! nightlyToolchain ) {
362
332
logger . error ( 'no nightly toolchain' ) ;
363
333
return false ;
@@ -371,7 +341,7 @@ export class Rustup {
371
341
*/
372
342
public canInstallRustAnalysis ( ) : boolean {
373
343
const logger = this . logger . createChildLogger ( 'canInstallRustAnalysis: ' ) ;
374
- const nightlyToolchain = this . getNightlyToolchain ( logger ) ;
344
+ const nightlyToolchain = this . getUserNightlyToolchain ( ) ;
375
345
if ( ! nightlyToolchain ) {
376
346
logger . error ( 'no nightly toolchain' ) ;
377
347
return false ;
@@ -502,20 +472,15 @@ export class Rustup {
502
472
* @param logger A value for the field `logger`
503
473
* @param pathToRustcSysRoot A value for the field `pathToRustcSysRoot`
504
474
* @param pathToRustSourceCode A value for the field `pathToRustSourceCode`
505
- * @param pathToRlsExecutable A value fo the field `pathToRlsExecutable`
506
475
*/
507
476
private constructor ( logger : ChildLogger ) {
508
477
this . logger = logger ;
509
478
this . pathToRustcSysRoot = undefined ;
510
479
this . pathToRustSourceCode = undefined ;
511
- this . pathToRlsExecutable = undefined ;
512
480
this . components = { } ;
513
481
this . toolchains = [ ] ;
514
482
this . _userToolchain = getUserToolchain ( ) ;
515
- }
516
-
517
- private getNightlyToolchains ( ) : Toolchain [ ] {
518
- return this . toolchains . filter ( t => t . channel === 'nightly' ) ;
483
+ this . _userNightlyToolchain = getUserNightlyToolchain ( ) ;
519
484
}
520
485
521
486
/**
@@ -580,12 +545,12 @@ function getUserConfiguration(): any {
580
545
return rustupConfiguration ;
581
546
}
582
547
583
- function getUserToolchain ( ) : Toolchain | undefined {
548
+ function getToolchainFromConfigurationParameter ( parameter : string ) : Toolchain | undefined {
584
549
const rustupConfiguration = getUserConfiguration ( ) ;
585
550
if ( ! rustupConfiguration ) {
586
551
return undefined ;
587
552
}
588
- const toolchainAsString = rustupConfiguration . toolchain ;
553
+ const toolchainAsString = rustupConfiguration [ parameter ] ;
589
554
if ( ! toolchainAsString ) {
590
555
return undefined ;
591
556
}
@@ -597,6 +562,14 @@ function getUserToolchain(): Toolchain | undefined {
597
562
}
598
563
}
599
564
565
+ function getUserNightlyToolchain ( ) : Toolchain | undefined {
566
+ return getToolchainFromConfigurationParameter ( 'nightlyToolchain' ) ;
567
+ }
568
+
569
+ function getUserToolchain ( ) : Toolchain | undefined {
570
+ return getToolchainFromConfigurationParameter ( 'toolchain' ) ;
571
+ }
572
+
600
573
function updateUserConfigurationParameter ( updateParameter : ( c : any ) => void ) : void {
601
574
let configuration = getUserConfiguration ( ) ;
602
575
if ( ! configuration ) {
0 commit comments