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

Use the user's default toolchain #180

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
},
"rust-client.channel": {
"type": "string",
"default": "nightly",
"default": "default",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use null rather than "default"

"description": "Rust channel to install RLS from."
},
"rust-client.rls-name": {
Expand Down
28 changes: 26 additions & 2 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

'use strict';

import { execSync } from 'child_process';

import { workspace, WorkspaceConfiguration } from 'vscode';
import { RevealOutputChannelOn } from 'vscode-languageclient';

Expand Down Expand Up @@ -58,15 +60,37 @@ export class RLSConfiguration {
this.revealOutputChannelOn = RLSConfiguration.readRevealOutputChannelOn(configuration);
this.updateOnStartup = configuration.get<boolean>('rust-client.updateOnStartup', true);

this.channel = configuration.get('rust-client.channel', 'nightly');
this.componentName = configuration.get('rust-client.rls-name', 'rls');
this.channel = configuration.get('rust-client.channel', 'default');
if (this.channel === 'default') {
try {
this.channel = RLSConfiguration.defaultChannel(this.rustupPath);
} catch (e) {
console.log(e);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this code to rustup.rs?

Copy link
Author

@lvillani lvillani Nov 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about moving it there but most of the code in rustup.ts relies on the RLSConfiguration object being already initialised, and is async. I thought this code would be inconsistent with the rest of the code there. I have no problem moving it there though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're using RLSConfiguration here too though? I don't think that whether the code is sync or async should make too much difference as to where it should live.


this.componentName = configuration.get('rust-client.rls-name', 'rls-preview');

// Hidden options that are not exposed to the user
this.rlsPath = configuration.get('rls.path', null);
this.rlsRoot = configuration.get('rls.root', null);
}

private static readRevealOutputChannelOn(configuration: WorkspaceConfiguration) {
const setting = configuration.get<string>('rust-client.revealOutputChannelOn', 'never');
return fromStringToRevealOutputChannelOn(setting);
}

private static defaultChannel(rustupPath: string): string {
const stdout = execSync(rustupPath + ' toolchain list').toString();
const matches = stdout.match(/^(.*) \(default\)$/m);

if (matches === null) {
throw new Error('Unable to determine default toolchain');
} else if (matches.length !== 2) {
throw new Error('Found unexpected number of default toolchains');
}

return matches[1];
}
}