mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Improve NixOS handling
This commit is contained in:
parent
e97569c998
commit
3835b3790e
1 changed files with 34 additions and 29 deletions
|
@ -27,7 +27,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
async function tryActivate(context: vscode.ExtensionContext) {
|
async function tryActivate(context: vscode.ExtensionContext) {
|
||||||
const config = new Config(context);
|
const config = new Config(context);
|
||||||
const state = new PersistentState(context.globalState);
|
const state = new PersistentState(context.globalState);
|
||||||
const serverPath = await bootstrap(config, state).catch(err => {
|
const serverPath = await bootstrap(context, config, state).catch(err => {
|
||||||
let message = "bootstrap error. ";
|
let message = "bootstrap error. ";
|
||||||
|
|
||||||
if (err.code === "EBUSY" || err.code === "ETXTBSY" || err.code === "EPERM") {
|
if (err.code === "EBUSY" || err.code === "ETXTBSY" || err.code === "EPERM") {
|
||||||
|
@ -157,8 +157,6 @@ export async function deactivate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bootstrap(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string> {
|
async function bootstrap(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string> {
|
||||||
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
|
|
||||||
|
|
||||||
const path = await getServer(context, config, state);
|
const path = await getServer(context, config, state);
|
||||||
if (!path) {
|
if (!path) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -244,7 +242,33 @@ async function getServer(context: vscode.ExtensionContext, config: Config, state
|
||||||
"arm64 darwin": "aarch64-apple-darwin",
|
"arm64 darwin": "aarch64-apple-darwin",
|
||||||
};
|
};
|
||||||
let platform = platforms[`${process.arch} ${process.platform}`];
|
let platform = platforms[`${process.arch} ${process.platform}`];
|
||||||
if (platform === undefined) {
|
if (platform) {
|
||||||
|
if (platform === "x86_64-unknown-linux-gnu" && isMusl()) {
|
||||||
|
platform = "x86_64-unknown-linux-musl";
|
||||||
|
}
|
||||||
|
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
|
||||||
|
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
|
||||||
|
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
|
||||||
|
if (bundledExists) {
|
||||||
|
let server = bundled;
|
||||||
|
if (await isNixOs()) {
|
||||||
|
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
|
||||||
|
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
|
||||||
|
let exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
|
||||||
|
if (exists && config.package.version !== state.serverVersion) {
|
||||||
|
await vscode.workspace.fs.delete(dest);
|
||||||
|
exists = false;
|
||||||
|
}
|
||||||
|
if (!exists) {
|
||||||
|
await vscode.workspace.fs.copy(bundled, dest);
|
||||||
|
await patchelf(dest);
|
||||||
|
server = dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await state.updateServerVersion(config.package.version);
|
||||||
|
return server.fsPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
await vscode.window.showErrorMessage(
|
await vscode.window.showErrorMessage(
|
||||||
"Unfortunately we don't ship binaries for your platform yet. " +
|
"Unfortunately we don't ship binaries for your platform yet. " +
|
||||||
"You need to manually clone rust-analyzer repository and " +
|
"You need to manually clone rust-analyzer repository and " +
|
||||||
|
@ -255,25 +279,6 @@ async function getServer(context: vscode.ExtensionContext, config: Config, state
|
||||||
);
|
);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (platform === "x86_64-unknown-linux-gnu" && isMusl()) {
|
|
||||||
platform = "x86_64-unknown-linux-musl";
|
|
||||||
}
|
|
||||||
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
|
|
||||||
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
|
|
||||||
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
|
|
||||||
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
|
|
||||||
const exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
|
|
||||||
if (bundledExists) {
|
|
||||||
if (!await isNixOs()) {
|
|
||||||
return bundled.fsPath;
|
|
||||||
}
|
|
||||||
if (!exists || config.package.version !== state.serverVersion) {
|
|
||||||
await vscode.workspace.fs.copy(bundled, dest);
|
|
||||||
await patchelf(dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dest.fsPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
function serverPath(config: Config): string | null {
|
function serverPath(config: Config): string | null {
|
||||||
return process.env.__RA_LSP_SERVER_DEBUG ?? config.serverPath;
|
return process.env.__RA_LSP_SERVER_DEBUG ?? config.serverPath;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue