Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit ec68f30

Browse files
authored
New configuration parameter "forceLegacyMode" (#216)
1 parent ab7edeb commit ec68f30

File tree

4 files changed

+67
-24
lines changed

4 files changed

+67
-24
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@
165165
"title": "Rust extension configuration",
166166
"type": "object",
167167
"properties": {
168+
"rust.forceLegacyMode": {
169+
"type": [
170+
"boolean",
171+
"null"
172+
],
173+
"default": null,
174+
"description": "Flag indicating if the extension shouldn't try to run RLS. By default, it is false"
175+
},
168176
"rust.racerPath": {
169177
"type": [
170178
"string",

src/components/configuration/Configuration.ts

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ export enum ActionOnStartingCommandIfThereIsRunningCommand {
3030
ShowDialogToLetUserDecide
3131
}
3232

33+
export enum Mode {
34+
Legacy,
35+
RLS
36+
}
37+
3338
/**
3439
* The main class of the component `Configuration`.
3540
* This class contains code related to Configuration
3641
*/
3742
export class Configuration {
43+
private _mode: Mode | undefined;
44+
private _isForcedLegacyMode: boolean;
3845
private logger: ChildLogger;
3946

4047
private rustInstallation: Rustup | NotRustup | undefined;
@@ -71,33 +78,28 @@ export class Configuration {
7178
*/
7279
public static async create(logger: ChildLogger): Promise<Configuration> {
7380
const rustcSysRoot: string | undefined = await this.loadRustcSysRoot();
74-
7581
const createRustInstallationPromise = async () => {
7682
if (!rustcSysRoot) {
7783
return undefined;
7884
}
79-
8085
if (Rustup.doesManageRustcSysRoot(rustcSysRoot)) {
8186
return await Rustup.create(logger.createChildLogger('Rustup: '), rustcSysRoot);
8287
} else {
8388
return new NotRustup(rustcSysRoot);
8489
}
8590
};
86-
8791
const rustInstallation: Rustup | NotRustup | undefined = await createRustInstallationPromise();
88-
8992
const pathToRustSourceCodeSpecifiedByUser = await this.checkPathToRustSourceCodeSpecifiedByUser();
90-
9193
const configuration = new Configuration(
9294
logger,
9395
rustInstallation,
9496
pathToRustSourceCodeSpecifiedByUser,
9597
undefined,
9698
undefined
9799
);
98-
99-
await configuration.updatePathToRlsExecutableSpecifiedByUser();
100-
100+
if (!configuration.isForcedLegacyMode()) {
101+
await configuration.updatePathToRlsExecutableSpecifiedByUser();
102+
}
101103
return configuration;
102104
}
103105

@@ -140,6 +142,22 @@ export class Configuration {
140142
);
141143
}
142144

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+
143161
/**
144162
* Returns a value of the field `pathToRacer`
145163
*/
@@ -251,14 +269,11 @@ export class Configuration {
251269

252270
public shouldExecuteCargoCommandInTerminal(): boolean {
253271
// When RLS is used any cargo command is executed in an integrated terminal.
254-
if (this.getRlsConfiguration() !== undefined) {
272+
if (this.mode() === Mode.RLS) {
255273
return true;
256274
}
257-
258275
const configuration = Configuration.getConfiguration();
259-
260276
const shouldExecuteCargoCommandInTerminal = configuration['executeCargoCommandInTerminal'];
261-
262277
return shouldExecuteCargoCommandInTerminal;
263278
}
264279

@@ -453,14 +468,22 @@ export class Configuration {
453468
rlsPathSpecifiedByUser: string | undefined,
454469
pathToRacer: string | undefined
455470
) {
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();
456483
this.logger = logger;
457-
458484
this.rustInstallation = rustInstallation;
459-
460485
this.pathToRustSourceCodeSpecifiedByUser = pathToRustSourceCodeSpecifiedByUser;
461-
462486
this.rlsPathSpecifiedByUser = rlsPathSpecifiedByUser;
463-
464487
this.racerPath = pathToRacer;
465488
}
466489

@@ -479,6 +502,10 @@ export class Configuration {
479502
*/
480503
private async updatePathToRlsExecutableSpecifiedByUser(): Promise<void> {
481504
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+
}
482509
this.rlsPathSpecifiedByUser = undefined;
483510
const rlsConfiguration = this.getRlsConfiguration();
484511
if (!rlsConfiguration) {

src/extension.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ExtensionContext, window, workspace } from 'vscode';
55

66
import { CargoManager, CommandInvocationReason } from './components/cargo/cargo_manager';
77

8-
import { Configuration } from './components/configuration/Configuration';
8+
import { Configuration, Mode } from './components/configuration/Configuration';
99

1010
import CurrentWorkingDirectoryManager from './components/configuration/current_working_directory_manager';
1111

@@ -129,7 +129,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
129129
const loggingManager = new LoggingManager();
130130
const logger = loggingManager.getLogger();
131131
const configuration = await Configuration.create(logger.createChildLogger('Configuration: '));
132-
if (!configuration.getPathToRlsExecutable()) {
132+
if (!configuration.getPathToRlsExecutable() && !configuration.isForcedLegacyMode()) {
133133
await handleMissingRls(logger, configuration);
134134
}
135135
const currentWorkingDirectoryManager = new CurrentWorkingDirectoryManager();
@@ -181,11 +181,10 @@ async function chooseModeAndRun(
181181
configuration: Configuration,
182182
currentWorkingDirectoryManager: CurrentWorkingDirectoryManager
183183
): Promise<void> {
184-
const pathToRlsExecutable = configuration.getPathToRlsExecutable();
185-
186-
if (pathToRlsExecutable) {
187-
runInRlsMode(context, logger, configuration, pathToRlsExecutable);
188-
} else {
184+
const rls: string | undefined = configuration.getPathToRlsExecutable();
185+
const isLegacyMode = configuration.isForcedLegacyMode() || !rls;
186+
if (isLegacyMode) {
187+
configuration.setMode(Mode.Legacy);
189188
const legacyModeManager = await LegacyModeManager.create(
190189
context,
191190
configuration,
@@ -194,6 +193,9 @@ async function chooseModeAndRun(
194193
);
195194

196195
await legacyModeManager.start();
196+
} else {
197+
configuration.setMode(Mode.RLS);
198+
runInRlsMode(context, logger, configuration, <string>rls);
197199
}
198200
}
199201

tslint.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939
]
4040
}
4141
],
42-
"prefer-const": [true, {"destructuring": "all"}],
42+
"prefer-const": [
43+
true,
44+
{
45+
"destructuring": "all"
46+
}
47+
],
4348
"no-any": false,
4449
"no-arg": true,
4550
"no-bitwise": false,
@@ -106,6 +111,7 @@
106111
"variable-name": [
107112
true,
108113
"check-format",
114+
"allow-leading-underscore",
109115
"ban-keywords"
110116
],
111117
"whitespace": [

0 commit comments

Comments
 (0)