mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Auto merge of #17667 - Veykril:r-a-component-override, r=Veykril
Use rustup rust-analyzer component when there is a toolchain file override for the opened workspace Fixes https://github.com/rust-lang/rust-analyzer/issues/17663
This commit is contained in:
commit
44f1eb415c
2 changed files with 44 additions and 18 deletions
|
@ -42,6 +42,7 @@ async function getServer(
|
||||||
enableProposedApi: boolean | undefined;
|
enableProposedApi: boolean | undefined;
|
||||||
} = context.extension.packageJSON;
|
} = context.extension.packageJSON;
|
||||||
|
|
||||||
|
// check if the server path is configured explicitly
|
||||||
const explicitPath = process.env["__RA_LSP_SERVER_DEBUG"] ?? config.serverPath;
|
const explicitPath = process.env["__RA_LSP_SERVER_DEBUG"] ?? config.serverPath;
|
||||||
if (explicitPath) {
|
if (explicitPath) {
|
||||||
if (explicitPath.startsWith("~/")) {
|
if (explicitPath.startsWith("~/")) {
|
||||||
|
@ -51,12 +52,29 @@ async function getServer(
|
||||||
}
|
}
|
||||||
if (packageJson.releaseTag === null) return "rust-analyzer";
|
if (packageJson.releaseTag === null) return "rust-analyzer";
|
||||||
|
|
||||||
|
if (vscode.workspace.workspaceFolders?.length === 1) {
|
||||||
|
// otherwise check if there is a toolchain override for the current vscode workspace
|
||||||
|
// and if the toolchain of this override has a rust-analyzer component
|
||||||
|
// if so, use the rust-analyzer component
|
||||||
|
const toolchainTomlExists = await fileExists(
|
||||||
|
vscode.Uri.joinPath(vscode.workspace.workspaceFolders[0]!.uri, "rust-toolchain.toml"),
|
||||||
|
);
|
||||||
|
if (toolchainTomlExists) {
|
||||||
|
const res = spawnSync("rustup", ["which", "rust-analyzer"], {
|
||||||
|
encoding: "utf8",
|
||||||
|
env: { ...process.env },
|
||||||
|
cwd: vscode.workspace.workspaceFolders[0]!.uri.fsPath,
|
||||||
|
});
|
||||||
|
if (!res.error && res.status === 0) {
|
||||||
|
return res.stdout.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally, use the bundled one
|
||||||
const ext = process.platform === "win32" ? ".exe" : "";
|
const ext = process.platform === "win32" ? ".exe" : "";
|
||||||
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
|
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
|
||||||
const bundledExists = await vscode.workspace.fs.stat(bundled).then(
|
const bundledExists = await fileExists(bundled);
|
||||||
() => true,
|
|
||||||
() => false,
|
|
||||||
);
|
|
||||||
if (bundledExists) {
|
if (bundledExists) {
|
||||||
let server = bundled;
|
let server = bundled;
|
||||||
if (await isNixOs()) {
|
if (await isNixOs()) {
|
||||||
|
@ -84,6 +102,13 @@ async function getServer(
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fileExists(uri: vscode.Uri) {
|
||||||
|
return await vscode.workspace.fs.stat(uri).then(
|
||||||
|
() => true,
|
||||||
|
() => false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function isValidExecutable(path: string, extraEnv: Env): boolean {
|
export function isValidExecutable(path: string, extraEnv: Env): boolean {
|
||||||
log.debug("Checking availability of a binary at", path);
|
log.debug("Checking availability of a binary at", path);
|
||||||
|
|
||||||
|
|
|
@ -187,19 +187,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._client) {
|
if (!this._client) {
|
||||||
this._serverPath = await bootstrap(this.extCtx, this.config, this.state).catch(
|
this._serverPath = await this.bootstrap();
|
||||||
(err) => {
|
|
||||||
let message = "bootstrap error. ";
|
|
||||||
|
|
||||||
message +=
|
|
||||||
'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). ';
|
|
||||||
message +=
|
|
||||||
'To enable verbose logs use { "rust-analyzer.trace.extension": true }';
|
|
||||||
|
|
||||||
log.error("Bootstrap error", err);
|
|
||||||
throw new Error(message);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
text(spawn(this._serverPath, ["--version"]).stdout.setEncoding("utf-8")).then(
|
text(spawn(this._serverPath, ["--version"]).stdout.setEncoding("utf-8")).then(
|
||||||
(data) => {
|
(data) => {
|
||||||
const prefix = `rust-analyzer `;
|
const prefix = `rust-analyzer `;
|
||||||
|
@ -291,6 +279,19 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
return this._client;
|
return this._client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async bootstrap(): Promise<string> {
|
||||||
|
return bootstrap(this.extCtx, this.config, this.state).catch((err) => {
|
||||||
|
let message = "bootstrap error. ";
|
||||||
|
|
||||||
|
message +=
|
||||||
|
'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). ';
|
||||||
|
message += 'To enable verbose logs use { "rust-analyzer.trace.extension": true }';
|
||||||
|
|
||||||
|
log.error("Bootstrap error", err);
|
||||||
|
throw new Error(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
log.info("Starting language client");
|
log.info("Starting language client");
|
||||||
const client = await this.getOrCreateClient();
|
const client = await this.getOrCreateClient();
|
||||||
|
@ -501,7 +502,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
|
|
||||||
const toggleCheckOnSave = this.config.checkOnSave ? "Disable" : "Enable";
|
const toggleCheckOnSave = this.config.checkOnSave ? "Disable" : "Enable";
|
||||||
statusBar.tooltip.appendMarkdown(
|
statusBar.tooltip.appendMarkdown(
|
||||||
`[Extension Info](command:analyzer.serverVersion "Show version and server binary info"): Version ${this.version}, Server Version ${this._serverVersion}` +
|
`[Extension Info](command:rust-analyzer.serverVersion "Show version and server binary info"): Version ${this.version}, Server Version ${this._serverVersion}` +
|
||||||
"\n\n---\n\n" +
|
"\n\n---\n\n" +
|
||||||
'[$(terminal) Open Logs](command:rust-analyzer.openLogs "Open the server logs")' +
|
'[$(terminal) Open Logs](command:rust-analyzer.openLogs "Open the server logs")' +
|
||||||
"\n\n" +
|
"\n\n" +
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue