Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit ac97f68

Browse files
committed
Simplify fetching active rustup channel
1 parent 9b3dec3 commit ac97f68

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/configuration.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export class RLSConfiguration {
5050
*/
5151
private static readChannel(
5252
wsPath: string,
53-
rustupConfiguration: RustupConfig,
53+
rustupPath: string,
5454
configuration: WorkspaceConfiguration,
5555
): string {
5656
const channel = configuration.get<string>('rust-client.channel');
5757
if (channel === 'default' || !channel) {
5858
try {
59-
return getActiveChannel(wsPath, rustupConfiguration);
59+
return getActiveChannel(wsPath, rustupPath);
6060
} catch (e) {
6161
// rustup might not be installed at the time the configuration is
6262
// initially loaded, so silently ignore the error and return a default value
@@ -94,7 +94,7 @@ export class RLSConfiguration {
9494
public get channel(): string {
9595
return RLSConfiguration.readChannel(
9696
this.wsPath,
97-
this.rustupConfig(true),
97+
this.rustupPath,
9898
this.configuration,
9999
);
100100
}
@@ -118,10 +118,9 @@ export class RLSConfiguration {
118118
return this.configuration.get<boolean>('rust-client.autoStartRls', true);
119119
}
120120

121-
// Added ignoreChannel for readChannel function. Otherwise we end in an infinite loop.
122-
public rustupConfig(ignoreChannel: boolean = false): RustupConfig {
121+
public rustupConfig(): RustupConfig {
123122
return {
124-
channel: ignoreChannel ? '' : this.channel,
123+
channel: this.channel,
125124
path: this.rustupPath,
126125
};
127126
}

src/rustup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export function hasRustup(config: RustupConfig): Promise<boolean> {
256256
* Returns active (including local overrides) toolchain, as specified by rustup.
257257
* May throw if rustup at specified path can't be executed.
258258
*/
259-
export function getActiveChannel(wsPath: string, config: RustupConfig): string {
259+
export function getActiveChannel(wsPath: string, rustupPath: string): string {
260260
// rustup info might differ depending on where it's executed
261261
// (e.g. when a toolchain is locally overriden), so executing it
262262
// under our current workspace root should give us close enough result
@@ -265,7 +265,7 @@ export function getActiveChannel(wsPath: string, config: RustupConfig): string {
265265
try {
266266
// `rustup show active-toolchain` is available since rustup 1.12.0
267267
activeChannel = child_process
268-
.execSync(`${config.path} show active-toolchain`, {
268+
.execSync(`${rustupPath} show active-toolchain`, {
269269
cwd: wsPath,
270270
})
271271
.toString()
@@ -278,7 +278,7 @@ export function getActiveChannel(wsPath: string, config: RustupConfig): string {
278278
} catch (e) {
279279
// Possibly an old rustup version, so try rustup show
280280
const showOutput = child_process
281-
.execSync(`${config.path} show`, {
281+
.execSync(`${rustupPath} show`, {
282282
cwd: wsPath,
283283
})
284284
.toString();

test/suite/rustup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ suite('Rustup Tests', () => {
1818
assert(rustupVersion.includes(`rustup ${version}`));
1919
});
2020
test('getActiveChannel', async () => {
21-
rustup.getActiveChannel('.', config);
21+
rustup.getActiveChannel('.', config.path);
2222
});
2323
});

0 commit comments

Comments
 (0)