@@ -35,8 +35,25 @@ export enum Mode {
35
35
RLS
36
36
}
37
37
38
+ /**
39
+ * Returns the representation of the specified mode suitable for being a value for the
40
+ * configuration parameter
41
+ * @param mode The mode which representation will be returned for
42
+ * @return The representation of the specified mode
43
+ */
44
+ export function asConfigurationParameterValue ( mode : Mode | undefined ) : string | null {
45
+ switch ( mode ) {
46
+ case Mode . Legacy :
47
+ return 'legacy' ;
48
+ case Mode . RLS :
49
+ return 'rls' ;
50
+ case undefined :
51
+ return null ;
52
+ }
53
+ }
54
+
38
55
namespace Properties {
39
- export const forceLegacyMode = 'forceLegacyMode ' ;
56
+ export const mode = 'mode ' ;
40
57
}
41
58
42
59
/**
@@ -45,9 +62,7 @@ namespace Properties {
45
62
*/
46
63
export class Configuration {
47
64
private _mode : Mode | undefined ;
48
- private _isForcedLegacyMode : boolean ;
49
65
private logger : ChildLogger ;
50
-
51
66
private rustInstallation : Rustup | NotRustup | undefined ;
52
67
53
68
/**
@@ -99,7 +114,7 @@ export class Configuration {
99
114
undefined ,
100
115
undefined
101
116
) ;
102
- if ( ! configuration . isForcedLegacyMode ( ) ) {
117
+ if ( configuration . _mode === Mode . RLS ) {
103
118
await configuration . updatePathToRlsExecutableSpecifiedByUser ( ) ;
104
119
}
105
120
return configuration ;
@@ -144,20 +159,26 @@ export class Configuration {
144
159
) ;
145
160
}
146
161
162
+ /**
163
+ * Returns the mode which the extension runs in
164
+ * @return The mode
165
+ */
147
166
public mode ( ) : Mode | undefined {
148
167
return this . _mode ;
149
168
}
150
169
170
+ /**
171
+ * Saves the specified mode in both the object and the configuration
172
+ * @param mode The mode
173
+ */
151
174
public setMode ( mode : Mode ) : void {
152
175
if ( this . _mode !== undefined ) {
153
- this . logger . createChildLogger ( `setMode(${ mode } ): ` ) . error ( ' this._mode !== undefined. The method should not have been called' ) ;
176
+ this . logger . error ( `setMode(${ mode } ): this._mode( ${ this . _mode } ) !== undefined. The method should not have been called` ) ;
154
177
return ;
155
178
}
156
179
this . _mode = mode ;
157
- }
158
-
159
- public isForcedLegacyMode ( ) : boolean {
160
- return this . _isForcedLegacyMode ;
180
+ const configuration = Configuration . getConfiguration ( ) ;
181
+ configuration . update ( Properties . mode , asConfigurationParameterValue ( mode ) , true ) ;
161
182
}
162
183
163
184
/**
@@ -368,12 +389,6 @@ export class Configuration {
368
389
}
369
390
}
370
391
371
- public setForceLegacyMode ( value : boolean ) : void {
372
- const configuration = Configuration . getConfiguration ( ) ;
373
- configuration . update ( Properties . forceLegacyMode , value , true ) ;
374
- this . _isForcedLegacyMode = value ;
375
- }
376
-
377
392
private static async loadRustcSysRoot ( ) : Promise < string | undefined > {
378
393
const executable = 'rustc' ;
379
394
@@ -478,18 +493,23 @@ export class Configuration {
478
493
rlsPathSpecifiedByUser : string | undefined ,
479
494
pathToRacer : string | undefined
480
495
) {
481
- function isForcedLegacyMode ( ) : boolean {
496
+ function mode ( ) : Mode | undefined {
482
497
const configuration = Configuration . getConfiguration ( ) ;
483
- const value : boolean | null | undefined = configuration [ Properties . forceLegacyMode ] ;
484
- if ( value ) {
485
- // It is actually `true`, but who knows how the code would behave later
486
- return value ;
498
+ const value : string | null | undefined = configuration [ Properties . mode ] ;
499
+ if ( typeof value === 'string' ) {
500
+ switch ( value ) {
501
+ case asConfigurationParameterValue ( Mode . Legacy ) :
502
+ return Mode . Legacy ;
503
+ case asConfigurationParameterValue ( Mode . RLS ) :
504
+ return Mode . RLS ;
505
+ default :
506
+ return undefined ;
507
+ }
487
508
} else {
488
- return false ;
509
+ return undefined ;
489
510
}
490
511
}
491
- this . _mode = undefined ;
492
- this . _isForcedLegacyMode = isForcedLegacyMode ( ) ;
512
+ this . _mode = mode ( ) ;
493
513
this . logger = logger ;
494
514
this . rustInstallation = rustInstallation ;
495
515
this . pathToRustSourceCodeSpecifiedByUser = pathToRustSourceCodeSpecifiedByUser ;
0 commit comments