Skip to content

Commit 3835b37

Browse files
committed
Improve NixOS handling
1 parent e97569c commit 3835b37

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

editors/code/src/main.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function activate(context: vscode.ExtensionContext) {
2727
async function tryActivate(context: vscode.ExtensionContext) {
2828
const config = new Config(context);
2929
const state = new PersistentState(context.globalState);
30-
const serverPath = await bootstrap(config, state).catch(err => {
30+
const serverPath = await bootstrap(context, config, state).catch(err => {
3131
let message = "bootstrap error. ";
3232

3333
if (err.code === "EBUSY" || err.code === "ETXTBSY" || err.code === "EPERM") {
@@ -157,8 +157,6 @@ export async function deactivate() {
157157
}
158158

159159
async function bootstrap(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string> {
160-
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
161-
162160
const path = await getServer(context, config, state);
163161
if (!path) {
164162
throw new Error(
@@ -244,35 +242,42 @@ async function getServer(context: vscode.ExtensionContext, config: Config, state
244242
"arm64 darwin": "aarch64-apple-darwin",
245243
};
246244
let platform = platforms[`${process.arch} ${process.platform}`];
247-
if (platform === undefined) {
248-
await vscode.window.showErrorMessage(
249-
"Unfortunately we don't ship binaries for your platform yet. " +
250-
"You need to manually clone rust-analyzer repository and " +
251-
"run `cargo xtask install --server` to build the language server from sources. " +
252-
"If you feel that your platform should be supported, please create an issue " +
253-
"about that [here](https://github.com/rust-analyzer/rust-analyzer/issues) and we " +
254-
"will consider it."
255-
);
256-
return undefined;
257-
}
258-
if (platform === "x86_64-unknown-linux-gnu" && isMusl()) {
259-
platform = "x86_64-unknown-linux-musl";
260-
}
261-
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
262-
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
263-
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
264-
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
265-
const exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
266-
if (bundledExists) {
267-
if (!await isNixOs()) {
268-
return bundled.fsPath;
245+
if (platform) {
246+
if (platform === "x86_64-unknown-linux-gnu" && isMusl()) {
247+
platform = "x86_64-unknown-linux-musl";
269248
}
270-
if (!exists || config.package.version !== state.serverVersion) {
271-
await vscode.workspace.fs.copy(bundled, dest);
272-
await patchelf(dest);
249+
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
250+
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
251+
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
252+
if (bundledExists) {
253+
let server = bundled;
254+
if (await isNixOs()) {
255+
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
256+
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
257+
let exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
258+
if (exists && config.package.version !== state.serverVersion) {
259+
await vscode.workspace.fs.delete(dest);
260+
exists = false;
261+
}
262+
if (!exists) {
263+
await vscode.workspace.fs.copy(bundled, dest);
264+
await patchelf(dest);
265+
server = dest;
266+
}
267+
}
268+
await state.updateServerVersion(config.package.version);
269+
return server.fsPath;
273270
}
274271
}
275-
return dest.fsPath;
272+
await vscode.window.showErrorMessage(
273+
"Unfortunately we don't ship binaries for your platform yet. " +
274+
"You need to manually clone rust-analyzer repository and " +
275+
"run `cargo xtask install --server` to build the language server from sources. " +
276+
"If you feel that your platform should be supported, please create an issue " +
277+
"about that [here](https://github.com/rust-analyzer/rust-analyzer/issues) and we " +
278+
"will consider it."
279+
);
280+
return undefined;
276281
}
277282

278283
function serverPath(config: Config): string | null {

0 commit comments

Comments
 (0)