Skip to content

Commit e97569c

Browse files
committed
Drop extensionUri copy
1 parent f63690c commit e97569c

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

editors/code/src/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ export class Config {
3030
} = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
3131

3232
readonly globalStorageUri: vscode.Uri;
33-
readonly installUri: vscode.Uri;
3433

3534
constructor(ctx: vscode.ExtensionContext) {
3635
this.globalStorageUri = ctx.globalStorageUri;
37-
this.installUri = ctx.extensionUri;
3836
vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, ctx.subscriptions);
3937
this.refreshLogging();
4038
}

editors/code/src/main.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,10 @@ export async function deactivate() {
156156
ctx = undefined;
157157
}
158158

159-
async function bootstrap(config: Config, state: PersistentState): Promise<string> {
159+
async function bootstrap(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string> {
160160
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
161-
const path = await bootstrapServer(config, state);
162-
return path;
163-
}
164161

165-
async function bootstrapServer(config: Config, state: PersistentState): Promise<string> {
166-
const path = await getServer(config, state);
162+
const path = await getServer(context, config, state);
167163
if (!path) {
168164
throw new Error(
169165
"Rust Analyzer Language Server is not available. " +
@@ -228,7 +224,7 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
228224
);
229225
}
230226

231-
async function getServer(config: Config, state: PersistentState): Promise<string | undefined> {
227+
async function getServer(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string | undefined> {
232228
const explicitPath = serverPath(config);
233229
if (explicitPath) {
234230
if (explicitPath.startsWith("~/")) {
@@ -264,14 +260,14 @@ async function getServer(config: Config, state: PersistentState): Promise<string
264260
}
265261
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
266262
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
267-
const bundled = vscode.Uri.joinPath(config.installUri, "server", `rust-analyzer${ext}`);
263+
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
268264
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
269265
const exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
270266
if (bundledExists) {
271267
if (!await isNixOs()) {
272268
return bundled.fsPath;
273269
}
274-
if (!exists) {
270+
if (!exists || config.package.version !== state.serverVersion) {
275271
await vscode.workspace.fs.copy(bundled, dest);
276272
await patchelf(dest);
277273
}

editors/code/src/persistent_state.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,18 @@ import { log } from './util';
33

44
export class PersistentState {
55
constructor(private readonly globalState: vscode.Memento) {
6+
const { serverVersion } = this;
7+
log.info("PersistentState:", { serverVersion });
8+
}
9+
10+
/**
11+
* Version of the extension that installed the server.
12+
* Used to check if we need to run patchelf again on NixOS.
13+
*/
14+
get serverVersion(): string | undefined {
15+
return this.globalState.get("serverVersion");
16+
}
17+
async updateServerVersion(value: string | undefined) {
18+
await this.globalState.update("serverVersion", value);
619
}
720
}

0 commit comments

Comments
 (0)