@@ -35,8 +35,25 @@ export enum Mode {
3535 RLS
3636}
3737
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+
3855namespace Properties {
39- export const forceLegacyMode = 'forceLegacyMode ' ;
56+ export const mode = 'mode ' ;
4057}
4158
4259/**
@@ -45,9 +62,7 @@ namespace Properties {
4562 */
4663export class Configuration {
4764 private _mode : Mode | undefined ;
48- private _isForcedLegacyMode : boolean ;
4965 private logger : ChildLogger ;
50-
5166 private rustInstallation : Rustup | NotRustup | undefined ;
5267
5368 /**
@@ -99,7 +114,7 @@ export class Configuration {
99114 undefined ,
100115 undefined
101116 ) ;
102- if ( ! configuration . isForcedLegacyMode ( ) ) {
117+ if ( configuration . _mode === Mode . RLS ) {
103118 await configuration . updatePathToRlsExecutableSpecifiedByUser ( ) ;
104119 }
105120 return configuration ;
@@ -144,20 +159,26 @@ export class Configuration {
144159 ) ;
145160 }
146161
162+ /**
163+ * Returns the mode which the extension runs in
164+ * @return The mode
165+ */
147166 public mode ( ) : Mode | undefined {
148167 return this . _mode ;
149168 }
150169
170+ /**
171+ * Saves the specified mode in both the object and the configuration
172+ * @param mode The mode
173+ */
151174 public setMode ( mode : Mode ) : void {
152175 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` ) ;
154177 return ;
155178 }
156179 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 ) ;
161182 }
162183
163184 /**
@@ -368,12 +389,6 @@ export class Configuration {
368389 }
369390 }
370391
371- public setForceLegacyMode ( value : boolean ) : void {
372- const configuration = Configuration . getConfiguration ( ) ;
373- configuration . update ( Properties . forceLegacyMode , value , true ) ;
374- this . _isForcedLegacyMode = value ;
375- }
376-
377392 private static async loadRustcSysRoot ( ) : Promise < string | undefined > {
378393 const executable = 'rustc' ;
379394
@@ -478,18 +493,23 @@ export class Configuration {
478493 rlsPathSpecifiedByUser : string | undefined ,
479494 pathToRacer : string | undefined
480495 ) {
481- function isForcedLegacyMode ( ) : boolean {
496+ function mode ( ) : Mode | undefined {
482497 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+ }
487508 } else {
488- return false ;
509+ return undefined ;
489510 }
490511 }
491- this . _mode = undefined ;
492- this . _isForcedLegacyMode = isForcedLegacyMode ( ) ;
512+ this . _mode = mode ( ) ;
493513 this . logger = logger ;
494514 this . rustInstallation = rustInstallation ;
495515 this . pathToRustSourceCodeSpecifiedByUser = pathToRustSourceCodeSpecifiedByUser ;
0 commit comments