@@ -30,11 +30,18 @@ export enum ActionOnStartingCommandIfThereIsRunningCommand {
30
30
ShowDialogToLetUserDecide
31
31
}
32
32
33
+ export enum Mode {
34
+ Legacy ,
35
+ RLS
36
+ }
37
+
33
38
/**
34
39
* The main class of the component `Configuration`.
35
40
* This class contains code related to Configuration
36
41
*/
37
42
export class Configuration {
43
+ private _mode : Mode | undefined ;
44
+ private _isForcedLegacyMode : boolean ;
38
45
private logger : ChildLogger ;
39
46
40
47
private rustInstallation : Rustup | NotRustup | undefined ;
@@ -71,33 +78,28 @@ export class Configuration {
71
78
*/
72
79
public static async create ( logger : ChildLogger ) : Promise < Configuration > {
73
80
const rustcSysRoot : string | undefined = await this . loadRustcSysRoot ( ) ;
74
-
75
81
const createRustInstallationPromise = async ( ) => {
76
82
if ( ! rustcSysRoot ) {
77
83
return undefined ;
78
84
}
79
-
80
85
if ( Rustup . doesManageRustcSysRoot ( rustcSysRoot ) ) {
81
86
return await Rustup . create ( logger . createChildLogger ( 'Rustup: ' ) , rustcSysRoot ) ;
82
87
} else {
83
88
return new NotRustup ( rustcSysRoot ) ;
84
89
}
85
90
} ;
86
-
87
91
const rustInstallation : Rustup | NotRustup | undefined = await createRustInstallationPromise ( ) ;
88
-
89
92
const pathToRustSourceCodeSpecifiedByUser = await this . checkPathToRustSourceCodeSpecifiedByUser ( ) ;
90
-
91
93
const configuration = new Configuration (
92
94
logger ,
93
95
rustInstallation ,
94
96
pathToRustSourceCodeSpecifiedByUser ,
95
97
undefined ,
96
98
undefined
97
99
) ;
98
-
99
- await configuration . updatePathToRlsExecutableSpecifiedByUser ( ) ;
100
-
100
+ if ( ! configuration . isForcedLegacyMode ( ) ) {
101
+ await configuration . updatePathToRlsExecutableSpecifiedByUser ( ) ;
102
+ }
101
103
return configuration ;
102
104
}
103
105
@@ -140,6 +142,22 @@ export class Configuration {
140
142
) ;
141
143
}
142
144
145
+ public mode ( ) : Mode | undefined {
146
+ return this . _mode ;
147
+ }
148
+
149
+ public setMode ( mode : Mode ) : void {
150
+ if ( this . _mode !== undefined ) {
151
+ this . logger . createChildLogger ( `setMode(${ mode } ): ` ) . error ( 'this._mode !== undefined. The method should not have been called' ) ;
152
+ return ;
153
+ }
154
+ this . _mode = mode ;
155
+ }
156
+
157
+ public isForcedLegacyMode ( ) : boolean {
158
+ return this . _isForcedLegacyMode ;
159
+ }
160
+
143
161
/**
144
162
* Returns a value of the field `pathToRacer`
145
163
*/
@@ -251,14 +269,11 @@ export class Configuration {
251
269
252
270
public shouldExecuteCargoCommandInTerminal ( ) : boolean {
253
271
// When RLS is used any cargo command is executed in an integrated terminal.
254
- if ( this . getRlsConfiguration ( ) !== undefined ) {
272
+ if ( this . mode ( ) === Mode . RLS ) {
255
273
return true ;
256
274
}
257
-
258
275
const configuration = Configuration . getConfiguration ( ) ;
259
-
260
276
const shouldExecuteCargoCommandInTerminal = configuration [ 'executeCargoCommandInTerminal' ] ;
261
-
262
277
return shouldExecuteCargoCommandInTerminal ;
263
278
}
264
279
@@ -453,14 +468,22 @@ export class Configuration {
453
468
rlsPathSpecifiedByUser : string | undefined ,
454
469
pathToRacer : string | undefined
455
470
) {
471
+ function isForcedLegacyMode ( ) : boolean {
472
+ const configuration = Configuration . getConfiguration ( ) ;
473
+ const value : boolean | null | undefined = configuration [ 'forceLegacyMode' ] ;
474
+ if ( value ) {
475
+ // It is actually `true`, but who knows how the code would behave later
476
+ return value ;
477
+ } else {
478
+ return false ;
479
+ }
480
+ }
481
+ this . _mode = undefined ;
482
+ this . _isForcedLegacyMode = isForcedLegacyMode ( ) ;
456
483
this . logger = logger ;
457
-
458
484
this . rustInstallation = rustInstallation ;
459
-
460
485
this . pathToRustSourceCodeSpecifiedByUser = pathToRustSourceCodeSpecifiedByUser ;
461
-
462
486
this . rlsPathSpecifiedByUser = rlsPathSpecifiedByUser ;
463
-
464
487
this . racerPath = pathToRacer ;
465
488
}
466
489
@@ -479,6 +502,10 @@ export class Configuration {
479
502
*/
480
503
private async updatePathToRlsExecutableSpecifiedByUser ( ) : Promise < void > {
481
504
const logger = this . logger . createChildLogger ( 'updatePathToRlsSpecifiedByUser: ' ) ;
505
+ if ( this . mode ( ) === Mode . Legacy ) {
506
+ logger . error ( 'this.mode() === Mode.Legacy. The method should not have been called' ) ;
507
+ return ;
508
+ }
482
509
this . rlsPathSpecifiedByUser = undefined ;
483
510
const rlsConfiguration = this . getRlsConfiguration ( ) ;
484
511
if ( ! rlsConfiguration ) {
0 commit comments