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

Support rust-analyzer as alternate LSP engine #793

Merged
merged 20 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
62 changes: 62 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
"installDevExtension": "npm install && ./node_modules/.bin/vsce package -o ./out/rls-vscode-dev.vsix && code --install-extension ./out/rls-vscode-dev.vsix"
},
"dependencies": {
"node-fetch": "^2.6.0",
"vscode-languageclient": "^6.0.0"
},
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/node": "^12.8.1",
"@types/node-fetch": "^2.5.7",
"@types/vscode": "^1.43.0",
"chai": "^4.2.0",
"glob": "^7.1.4",
Expand Down Expand Up @@ -160,6 +162,20 @@
"type": "object",
"title": "Rust configuration",
"properties": {
"rust-client.engine": {
"type": "string",
"enum": [
"rls",
"rust-analyzer"
],
"enumDescriptions": [
"Use the Rust Language Server (RLS)",
"EXPERIMENTAL: Use the rust-analyzer language server"
],
"default": "rls",
"description": "The underlying LSP server used to provide IDE support for Rust projects.",
"scope": "window"
},
"rust-client.logToFile": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -448,6 +464,22 @@
"default": true,
"description": "Show additional context in hover tooltips when available. This is often the type local variable declaration.",
"scope": "resource"
},
"rust.rust-analyzer": {
"type": "object",
"default": {},
"description": "Settings passed down to rust-analyzer server",
"scope": "resource"
},
"rust.rust-analyzer.releaseTag": {
"type": "string",
"default": "nightly",
"description": "Which binary release to download and use"
},
"rust.rust-analyzer.path": {
"type": ["string", "null"],
"default": null,
"description": "When specified, uses the rust-analyzer binary at a given path"
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export class RLSConfiguration {
*/
private static readChannel(
wsPath: string,
rustupConfiguration: RustupConfig,
rustupPath: string,
configuration: WorkspaceConfiguration,
): string {
const channel = configuration.get<string>('rust-client.channel');
if (channel === 'default' || !channel) {
try {
return getActiveChannel(wsPath, rustupConfiguration);
return getActiveChannel(wsPath, rustupPath);
} catch (e) {
// rustup might not be installed at the time the configuration is
// initially loaded, so silently ignore the error and return a default value
Expand All @@ -83,6 +83,13 @@ export class RLSConfiguration {
);
}

public get rustAnalyzer(): { path?: string; releaseTag: string } {
const cfg = this.configuration;
const releaseTag = cfg.get('rust.rust-analyzer.releaseTag', 'nightly');
const path = cfg.get<string>('rust.rust-analyzer.path');
return { releaseTag, ...{ path } };
}

public get revealOutputChannelOn(): RevealOutputChannelOn {
return RLSConfiguration.readRevealOutputChannelOn(this.configuration);
}
Expand All @@ -94,7 +101,7 @@ export class RLSConfiguration {
public get channel(): string {
return RLSConfiguration.readChannel(
this.wsPath,
this.rustupConfig(true),
this.rustupPath,
this.configuration,
);
}
Expand All @@ -106,17 +113,21 @@ export class RLSConfiguration {
return this.configuration.get<string>('rust-client.rlsPath');
}

/** Returns the language analysis engine to be used for the workspace */
public get engine(): 'rls' | 'rust-analyzer' {
return this.configuration.get('rust-client.engine') || 'rls';
}

/**
* Whether RLS should be automaticallystarted when opening a relevant Rust project.
*/
public get autoStartRls(): boolean {
return this.configuration.get<boolean>('rust-client.autoStartRls', true);
}

// Added ignoreChannel for readChannel function. Otherwise we end in an infinite loop.
public rustupConfig(ignoreChannel: boolean = false): RustupConfig {
public rustupConfig(): RustupConfig {
return {
channel: ignoreChannel ? '' : this.channel,
channel: this.channel,
path: this.rustupPath,
};
}
Expand Down
Loading