about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorLaurențiu Nicola <lnicola@dend.ro>2021-12-23 09:49:24 +0200
committerLaurențiu Nicola <lnicola@dend.ro>2021-12-23 13:10:50 +0200
commit3835b3790ea9ddcf97e992c640324744e7e5db49 (patch)
tree3cafd7753c5f0778f33cb0f7afe1ba1f9bad52cd /editors/code
parente97569c998e87288fe7730e1d8bed0def6bda120 (diff)
downloadrust-3835b3790ea9ddcf97e992c640324744e7e5db49.tar.gz
rust-3835b3790ea9ddcf97e992c640324744e7e5db49.zip
Improve NixOS handling
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/main.ts63
1 files changed, 34 insertions, 29 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 74fdc59a1ef..4628bf4b3c5 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -27,7 +27,7 @@ export async function activate(context: vscode.ExtensionContext) {
 async function tryActivate(context: vscode.ExtensionContext) {
     const config = new Config(context);
     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. ";
 
         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> {
-    await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
-
     const path = await getServer(context, config, state);
     if (!path) {
         throw new Error(
@@ -244,35 +242,42 @@ async function getServer(context: vscode.ExtensionContext, config: Config, state
         "arm64 darwin": "aarch64-apple-darwin",
     };
     let platform = platforms[`${process.arch} ${process.platform}`];
-    if (platform === undefined) {
-        await vscode.window.showErrorMessage(
-            "Unfortunately we don't ship binaries for your platform yet. " +
-            "You need to manually clone rust-analyzer repository and " +
-            "run `cargo xtask install --server` to build the language server from sources. " +
-            "If you feel that your platform should be supported, please create an issue " +
-            "about that [here](https://github.com/rust-analyzer/rust-analyzer/issues) and we " +
-            "will consider it."
-        );
-        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 (platform) {
+        if (platform === "x86_64-unknown-linux-gnu" && isMusl()) {
+            platform = "x86_64-unknown-linux-musl";
         }
-        if (!exists || config.package.version !== state.serverVersion) {
-            await vscode.workspace.fs.copy(bundled, dest);
-            await patchelf(dest);
+        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;
         }
     }
-    return dest.fsPath;
+    await vscode.window.showErrorMessage(
+        "Unfortunately we don't ship binaries for your platform yet. " +
+        "You need to manually clone rust-analyzer repository and " +
+        "run `cargo xtask install --server` to build the language server from sources. " +
+        "If you feel that your platform should be supported, please create an issue " +
+        "about that [here](https://github.com/rust-analyzer/rust-analyzer/issues) and we " +
+        "will consider it."
+    );
+    return undefined;
 }
 
 function serverPath(config: Config): string | null {