about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurențiu Nicola <lnicola@dend.ro>2021-12-23 08:44:23 +0200
committerLaurențiu Nicola <lnicola@dend.ro>2021-12-23 09:36:55 +0200
commite97569c998e87288fe7730e1d8bed0def6bda120 (patch)
tree110af3e5172cd08ef46389a43cb5c0c05f3f6d43
parentf63690c058dbffcf334e3eb67a73102b30504d14 (diff)
downloadrust-e97569c998e87288fe7730e1d8bed0def6bda120.tar.gz
rust-e97569c998e87288fe7730e1d8bed0def6bda120.zip
Drop extensionUri copy
-rw-r--r--editors/code/src/config.ts2
-rw-r--r--editors/code/src/main.ts14
-rw-r--r--editors/code/src/persistent_state.ts13
3 files changed, 18 insertions, 11 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 9ed573ccf5c..cdbaa67fe22 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -30,11 +30,9 @@ export class Config {
     } = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
 
     readonly globalStorageUri: vscode.Uri;
-    readonly installUri: vscode.Uri;
 
     constructor(ctx: vscode.ExtensionContext) {
         this.globalStorageUri = ctx.globalStorageUri;
-        this.installUri = ctx.extensionUri;
         vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, ctx.subscriptions);
         this.refreshLogging();
     }
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 06e231a9732..74fdc59a1ef 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -156,14 +156,10 @@ export async function deactivate() {
     ctx = undefined;
 }
 
-async function bootstrap(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 bootstrapServer(config, state);
-    return path;
-}
 
-async function bootstrapServer(config: Config, state: PersistentState): Promise<string> {
-    const path = await getServer(config, state);
+    const path = await getServer(context, config, state);
     if (!path) {
         throw new Error(
             "Rust Analyzer Language Server is not available. " +
@@ -228,7 +224,7 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
     );
 }
 
-async function getServer(config: Config, state: PersistentState): Promise<string | undefined> {
+async function getServer(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string | undefined> {
     const explicitPath = serverPath(config);
     if (explicitPath) {
         if (explicitPath.startsWith("~/")) {
@@ -264,14 +260,14 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     }
     const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
     const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
-    const bundled = vscode.Uri.joinPath(config.installUri, "server", `rust-analyzer${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) {
+        if (!exists || config.package.version !== state.serverVersion) {
             await vscode.workspace.fs.copy(bundled, dest);
             await patchelf(dest);
         }
diff --git a/editors/code/src/persistent_state.ts b/editors/code/src/persistent_state.ts
index f6d0a3d015f..3e86ed1e323 100644
--- a/editors/code/src/persistent_state.ts
+++ b/editors/code/src/persistent_state.ts
@@ -3,5 +3,18 @@ import { log } from './util';
 
 export class PersistentState {
     constructor(private readonly globalState: vscode.Memento) {
+        const { serverVersion } = this;
+        log.info("PersistentState:", { serverVersion });
+    }
+
+    /**
+     * Version of the extension that installed the server.
+     * Used to check if we need to run patchelf again on NixOS.
+     */
+    get serverVersion(): string | undefined {
+        return this.globalState.get("serverVersion");
+    }
+    async updateServerVersion(value: string | undefined) {
+        await this.globalState.update("serverVersion", value);
     }
 }