Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit fd01859

Browse filesBrowse files
authored
Enable users to specify toolchain to use (#267)
1 parent 6940183 commit fd01859
Copy full SHA for fd01859

File tree

8 files changed

+388
-91
lines changed
Filter options

8 files changed

+388
-91
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Common Configuration Parameters
2+
3+
## rustup
4+
5+
Users should adjust properties of this configuration parameter to customize rustup.
6+
7+
### toolchain
8+
9+
This configuration parameter specifies which toolchain the extension will invoke rustup with.
10+
It is used for getting sysroot, installing components.
11+
12+
However there are few exceptions. Currently RLS is available for nightly hence RLS and rust-analysis are installed for the nightly toolchain.

‎doc/main.md

Copy file name to clipboardExpand all lines: doc/main.md
+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ The chosen mode is stored in `"rust.mode"` and it can be changed by users.
2121

2222
Each mode is described in detail on its own page.
2323

24+
Some configuration parameters effect both modes. They are described [there](common_configuration_parameters.md).
25+
2426
Furthermore, the extension provides:
2527

2628
* [Linting (the showing of diagnostics in the active text editor)](linting.md)

‎package.json

Copy file name to clipboardExpand all lines: package.json
+14
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,20 @@
466466
},
467467
"type": "array"
468468
},
469+
"rust.rustup": {
470+
"default": null,
471+
"description": "rustup configuration",
472+
"properties": {
473+
"toolchain": {
474+
"default": null,
475+
"description": "The toolchain to use for installing components (rust-src), except RLS",
476+
"type": [
477+
"string",
478+
"null"
479+
]
480+
}
481+
}
482+
},
469483
"rust.rls": {
470484
"default": null,
471485
"description": "Rust Language Server configuration",

‎src/Toolchain.ts

Copy file name to clipboard
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
export class Toolchain {
2+
public static readonly defaultToolchainPrefix: string = ' (default)';
3+
4+
/**
5+
* "stable" in "stable-x86_64-pc-windows-msvc (default)"
6+
*/
7+
public readonly channel: string;
8+
9+
/**
10+
* "x86_64-pc-windows-msvc" in "stable-x86_64-pc-windows-msvc (default)"
11+
* `undefined` in "stable"
12+
*/
13+
public readonly host: string | undefined;
14+
15+
/**
16+
* true in "stable-x86_64-pc-windows-msvc (default)".
17+
* false in "stable-x86_64-pc-windows-msvc"
18+
*/
19+
public readonly isDefault: boolean;
20+
21+
/**
22+
* Tries to parse the text and if returns the toolchain parsed from the text
23+
* @param text The text to parse
24+
* @return the toolchain or undefined
25+
*/
26+
public static parse(text: string): Toolchain | undefined {
27+
const sepIndex = text.indexOf('-');
28+
const channelEnd = sepIndex === -1 ? undefined : sepIndex;
29+
const channel = text.substring(0, channelEnd);
30+
if (channelEnd === undefined) {
31+
// The text represents the toolchain with the only channel.
32+
return new Toolchain(channel, undefined, false);
33+
}
34+
const spaceIndex = text.indexOf(' ', sepIndex);
35+
const hostEnd = spaceIndex === -1 ? undefined : spaceIndex;
36+
const host = text.substring(sepIndex + 1, hostEnd);
37+
const isDefault = text.endsWith(Toolchain.defaultToolchainPrefix);
38+
return new Toolchain(channel, host, isDefault);
39+
}
40+
41+
public equals(toolchain: Toolchain): boolean {
42+
return this.channel === toolchain.channel && this.host === toolchain.host;
43+
}
44+
45+
public toString(includeHost: boolean, includeIsDefault: boolean): string {
46+
let s = this.channel.concat();
47+
if (includeHost && this.host) {
48+
s += '-';
49+
s += this.host;
50+
}
51+
if (includeIsDefault && this.isDefault) {
52+
s += Toolchain.defaultToolchainPrefix;
53+
}
54+
return s;
55+
}
56+
57+
private constructor(channel: string, host: string | undefined, isDefault: boolean) {
58+
this.channel = channel;
59+
this.host = host;
60+
this.isDefault = isDefault;
61+
}
62+
}

‎src/components/completion/completion_manager.ts

Copy file name to clipboardExpand all lines: src/components/completion/completion_manager.ts
+24-13
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class CompletionManager {
9191
logger.debug('racer is not installed');
9292
return;
9393
}
94-
const isSourceCodeAvailable: boolean = this.ensureSourceCodeIsAvailable();
94+
const isSourceCodeAvailable: boolean = await this.ensureSourceCodeIsAvailable();
9595
if (!isSourceCodeAvailable) {
9696
logger.debug('Rust\'s source is not installed');
9797
return;
@@ -123,22 +123,33 @@ export class CompletionManager {
123123
* Ensures that Rust's source code is available to use
124124
* @returns flag indicating whether the source code if available or not
125125
*/
126-
private ensureSourceCodeIsAvailable(): boolean {
126+
private async ensureSourceCodeIsAvailable(): Promise<boolean> {
127+
const logger = this.logger.createChildLogger('ensureSourceCodeIsAvailable: ');
127128
if (this._rustSource.getPath()) {
129+
logger.debug('sources is available');
128130
return true;
129131
}
130-
if (this._rustup) {
131-
// tslint:disable-next-line
132-
const message = 'You are using rustup, but don\'t have installed source code. Do you want to install it?';
133-
window.showErrorMessage(message, 'Yes').then(chosenItem => {
134-
if (chosenItem === 'Yes') {
135-
const terminal = window.createTerminal('Rust source code installation');
136-
terminal.sendText('rustup component add rust-src');
137-
terminal.show();
138-
}
139-
});
132+
if (!this._rustup) {
133+
logger.error('rustup is undefined');
134+
return false;
135+
}
136+
// tslint:disable-next-line
137+
const message = 'You are using rustup, but don\'t have installed source code. Do you want to install it?';
138+
const choice = await window.showErrorMessage(message, 'Yes');
139+
if (choice === 'Yes') {
140+
logger.debug('the user agreed to install rust-src');
141+
const rustSrcInstalled = await this._rustup.installRustSrc();
142+
if (rustSrcInstalled) {
143+
logger.debug('rust-src has been installed');
144+
return true;
145+
} else {
146+
logger.error('rust-src has not been installed');
147+
return false;
148+
}
149+
} else {
150+
logger.debug('the user dismissed the dialog');
151+
return false;
140152
}
141-
return false;
142153
}
143154

144155
/**

‎src/components/configuration/Configuration.ts

Copy file name to clipboardExpand all lines: src/components/configuration/Configuration.ts
+9-13
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class Configuration {
5959
}
6060

6161
public static getPathConfigParameter(parameterName: string): string | undefined {
62-
const parameter = this.getStringParameter(parameterName);
62+
const parameter = this.getStringConfigParameter(parameterName);
6363
if (parameter) {
6464
return expandTilde(parameter);
6565
} else {
@@ -76,6 +76,12 @@ export class Configuration {
7676
}
7777
}
7878

79+
public static getStringConfigParameter(parameterName: string): string | undefined {
80+
const configuration = workspace.getConfiguration('rust');
81+
const parameter = configuration.get<string>(parameterName);
82+
return parameter;
83+
}
84+
7985
/**
8086
* Creates a new instance of the class.
8187
* @param logger A value for the field `logger`
@@ -170,10 +176,8 @@ export class Configuration {
170176
return shouldExecuteCargoCommandInTerminal;
171177
}
172178

173-
public getActionOnSave(): string | null {
174-
const actionOnSave = Configuration.getStringParameter('actionOnSave');
175-
176-
return actionOnSave;
179+
public getActionOnSave(): string | undefined {
180+
return Configuration.getStringConfigParameter('actionOnSave');
177181
}
178182

179183
public shouldShowRunningCargoTaskOutputChannel(): boolean {
@@ -240,12 +244,4 @@ export class Configuration {
240244
return ActionOnStartingCommandIfThereIsRunningCommand.IgnoreNewCommand;
241245
}
242246
}
243-
244-
private static getStringParameter(parameterName: string): string | null {
245-
const configuration = workspace.getConfiguration('rust');
246-
247-
const parameter: string | null = configuration[parameterName];
248-
249-
return parameter;
250-
}
251247
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.