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

Ask user to choose mode #251

Merged
merged 1 commit into from
May 26, 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
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,18 @@
"title": "Rust extension configuration",
"type": "object",
"properties": {
"rust.forceLegacyMode": {
"rust.mode": {
"type": [
"boolean",
"string",
"null"
],
"default": null,
"description": "Flag indicating if the extension shouldn't try to run RLS. By default, it is false"
"description": "The mode in which the extension will function",
"enum": [
"legacy",
"rls",
null
]
},
"rust.racerPath": {
"type": [
Expand Down
66 changes: 43 additions & 23 deletions src/components/configuration/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,25 @@ export enum Mode {
RLS
}

/**
* Returns the representation of the specified mode suitable for being a value for the
* configuration parameter
* @param mode The mode which representation will be returned for
* @return The representation of the specified mode
*/
export function asConfigurationParameterValue(mode: Mode | undefined): string | null {
switch (mode) {
case Mode.Legacy:
return 'legacy';
case Mode.RLS:
return 'rls';
case undefined:
return null;
}
}

namespace Properties {
export const forceLegacyMode = 'forceLegacyMode';
export const mode = 'mode';
}

/**
Expand All @@ -45,9 +62,7 @@ namespace Properties {
*/
export class Configuration {
private _mode: Mode | undefined;
private _isForcedLegacyMode: boolean;
private logger: ChildLogger;

private rustInstallation: Rustup | NotRustup | undefined;

/**
Expand Down Expand Up @@ -99,7 +114,7 @@ export class Configuration {
undefined,
undefined
);
if (!configuration.isForcedLegacyMode()) {
if (configuration._mode === Mode.RLS) {
await configuration.updatePathToRlsExecutableSpecifiedByUser();
}
return configuration;
Expand Down Expand Up @@ -144,20 +159,26 @@ export class Configuration {
);
}

/**
* Returns the mode which the extension runs in
* @return The mode
*/
public mode(): Mode | undefined {
return this._mode;
}

/**
* Saves the specified mode in both the object and the configuration
* @param mode The 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');
this.logger.error(`setMode(${mode}): this._mode(${this._mode}) !== undefined. The method should not have been called`);
return;
}
this._mode = mode;
}

public isForcedLegacyMode(): boolean {
return this._isForcedLegacyMode;
const configuration = Configuration.getConfiguration();
configuration.update(Properties.mode, asConfigurationParameterValue(mode), true);
}

/**
Expand Down Expand Up @@ -368,12 +389,6 @@ export class Configuration {
}
}

public setForceLegacyMode(value: boolean): void {
const configuration = Configuration.getConfiguration();
configuration.update(Properties.forceLegacyMode, value, true);
this._isForcedLegacyMode = value;
}

private static async loadRustcSysRoot(): Promise<string | undefined> {
const executable = 'rustc';

Expand Down Expand Up @@ -478,18 +493,23 @@ export class Configuration {
rlsPathSpecifiedByUser: string | undefined,
pathToRacer: string | undefined
) {
function isForcedLegacyMode(): boolean {
function mode(): Mode | undefined {
const configuration = Configuration.getConfiguration();
const value: boolean | null | undefined = configuration[Properties.forceLegacyMode];
if (value) {
// It is actually `true`, but who knows how the code would behave later
return value;
const value: string | null | undefined = configuration[Properties.mode];
if (typeof value === 'string') {
switch (value) {
case asConfigurationParameterValue(Mode.Legacy):
return Mode.Legacy;
case asConfigurationParameterValue(Mode.RLS):
return Mode.RLS;
default:
return undefined;
}
} else {
return false;
return undefined;
}
}
this._mode = undefined;
this._isForcedLegacyMode = isForcedLegacyMode();
this._mode = mode();
this.logger = logger;
this.rustInstallation = rustInstallation;
this.pathToRustSourceCodeSpecifiedByUser = pathToRustSourceCodeSpecifiedByUser;
Expand Down
8 changes: 8 additions & 0 deletions src/components/configuration/Rustup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ export class Rustup {
return this.isComponentInstalled(Rustup.getRlsComponentName());
}

/**
* Returns whether "rust-analysis" is installed
* @return The flag indicating whether "rust-analysis" is installed
*/
public isRustAnalysisInstalled(): boolean {
return this.isComponentInstalled(Rustup.getRustAnalysisComponentName());
}

/**
* Returns true if the component `rust-analysis` can be installed otherwise false.
* If the component is already installed, the method returns false
Expand Down
Loading