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

New configuration parameter "forceLegacyMode" #216

Merged
merged 1 commit into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
"title": "Rust extension configuration",
"type": "object",
"properties": {
"rust.forceLegacyMode": {
"type": [
"boolean",
"null"
],
"default": null,
"description": "Flag indicating if the extension shouldn't try to run RLS. By default, it is false"
},
"rust.racerPath": {
"type": [
"string",
Expand Down
59 changes: 43 additions & 16 deletions src/components/configuration/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ export enum ActionOnStartingCommandIfThereIsRunningCommand {
ShowDialogToLetUserDecide
}

export enum Mode {
Legacy,
RLS
}

/**
* The main class of the component `Configuration`.
* This class contains code related to Configuration
*/
export class Configuration {
private _mode: Mode | undefined;
private _isForcedLegacyMode: boolean;
private logger: ChildLogger;

private rustInstallation: Rustup | NotRustup | undefined;
Expand Down Expand Up @@ -71,33 +78,28 @@ export class Configuration {
*/
public static async create(logger: ChildLogger): Promise<Configuration> {
const rustcSysRoot: string | undefined = await this.loadRustcSysRoot();

const createRustInstallationPromise = async () => {
if (!rustcSysRoot) {
return undefined;
}

if (Rustup.doesManageRustcSysRoot(rustcSysRoot)) {
return await Rustup.create(logger.createChildLogger('Rustup: '), rustcSysRoot);
} else {
return new NotRustup(rustcSysRoot);
}
};

const rustInstallation: Rustup | NotRustup | undefined = await createRustInstallationPromise();

const pathToRustSourceCodeSpecifiedByUser = await this.checkPathToRustSourceCodeSpecifiedByUser();

const configuration = new Configuration(
logger,
rustInstallation,
pathToRustSourceCodeSpecifiedByUser,
undefined,
undefined
);

await configuration.updatePathToRlsExecutableSpecifiedByUser();

if (!configuration.isForcedLegacyMode()) {
await configuration.updatePathToRlsExecutableSpecifiedByUser();
}
return configuration;
}

Expand Down Expand Up @@ -140,6 +142,22 @@ export class Configuration {
);
}

public mode(): Mode | undefined {
return this._mode;
}

public setMode(mode: Mode): void {
if (this._mode !== undefined) {
this.logger.createChildLogger(`setMode(${mode}): `).error('this._mode !== undefined. The method should not have been called');
return;
}
this._mode = mode;
}

public isForcedLegacyMode(): boolean {
return this._isForcedLegacyMode;
}

/**
* Returns a value of the field `pathToRacer`
*/
Expand Down Expand Up @@ -251,14 +269,11 @@ export class Configuration {

public shouldExecuteCargoCommandInTerminal(): boolean {
// When RLS is used any cargo command is executed in an integrated terminal.
if (this.getRlsConfiguration() !== undefined) {
if (this.mode() === Mode.RLS) {
return true;
}

const configuration = Configuration.getConfiguration();

const shouldExecuteCargoCommandInTerminal = configuration['executeCargoCommandInTerminal'];

return shouldExecuteCargoCommandInTerminal;
}

Expand Down Expand Up @@ -453,14 +468,22 @@ export class Configuration {
rlsPathSpecifiedByUser: string | undefined,
pathToRacer: string | undefined
) {
function isForcedLegacyMode(): boolean {
const configuration = Configuration.getConfiguration();
const value: boolean | null | undefined = configuration['forceLegacyMode'];
if (value) {
// It is actually `true`, but who knows how the code would behave later
return value;
} else {
return false;
}
}
this._mode = undefined;
this._isForcedLegacyMode = isForcedLegacyMode();
this.logger = logger;

this.rustInstallation = rustInstallation;

this.pathToRustSourceCodeSpecifiedByUser = pathToRustSourceCodeSpecifiedByUser;

this.rlsPathSpecifiedByUser = rlsPathSpecifiedByUser;

this.racerPath = pathToRacer;
}

Expand All @@ -479,6 +502,10 @@ export class Configuration {
*/
private async updatePathToRlsExecutableSpecifiedByUser(): Promise<void> {
const logger = this.logger.createChildLogger('updatePathToRlsSpecifiedByUser: ');
if (this.mode() === Mode.Legacy) {
logger.error('this.mode() === Mode.Legacy. The method should not have been called');
return;
}
this.rlsPathSpecifiedByUser = undefined;
const rlsConfiguration = this.getRlsConfiguration();
if (!rlsConfiguration) {
Expand Down
16 changes: 9 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExtensionContext, window, workspace } from 'vscode';

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

import { Configuration } from './components/configuration/Configuration';
import { Configuration, Mode } from './components/configuration/Configuration';

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

Expand Down Expand Up @@ -129,7 +129,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
const loggingManager = new LoggingManager();
const logger = loggingManager.getLogger();
const configuration = await Configuration.create(logger.createChildLogger('Configuration: '));
if (!configuration.getPathToRlsExecutable()) {
if (!configuration.getPathToRlsExecutable() && !configuration.isForcedLegacyMode()) {
await handleMissingRls(logger, configuration);
}
const currentWorkingDirectoryManager = new CurrentWorkingDirectoryManager();
Expand Down Expand Up @@ -181,11 +181,10 @@ async function chooseModeAndRun(
configuration: Configuration,
currentWorkingDirectoryManager: CurrentWorkingDirectoryManager
): Promise<void> {
const pathToRlsExecutable = configuration.getPathToRlsExecutable();

if (pathToRlsExecutable) {
runInRlsMode(context, logger, configuration, pathToRlsExecutable);
} else {
const rls: string | undefined = configuration.getPathToRlsExecutable();
const isLegacyMode = configuration.isForcedLegacyMode() || !rls;
if (isLegacyMode) {
configuration.setMode(Mode.Legacy);
const legacyModeManager = await LegacyModeManager.create(
context,
configuration,
Expand All @@ -194,6 +193,9 @@ async function chooseModeAndRun(
);

await legacyModeManager.start();
} else {
configuration.setMode(Mode.RLS);
runInRlsMode(context, logger, configuration, <string>rls);
}
}

Expand Down
8 changes: 7 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
]
}
],
"prefer-const": [true, {"destructuring": "all"}],
"prefer-const": [
true,
{
"destructuring": "all"
}
],
"no-any": false,
"no-arg": true,
"no-bitwise": false,
Expand Down Expand Up @@ -106,6 +111,7 @@
"variable-name": [
true,
"check-format",
"allow-leading-underscore",
"ban-keywords"
],
"whitespace": [
Expand Down