mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-24 12:24:11 +00:00
Rewrite auto-update
Everything now happens in main.ts, in the bootstrap family of functions. The current flow is: * check everything only on extension installation. * if the user is on nightly channel, try to download the nightly extension and reload. * when we install nightly extension, we persist its release id, so that we can check if the current release is different. * if server binary was not downloaded by the current version of the extension, redownload it (we persist the version of ext that downloaded the server).
This commit is contained in:
parent
f0a1b64d7e
commit
fb6e655de8
13 changed files with 270 additions and 696 deletions
|
@ -1,49 +1,41 @@
|
|||
import * as vscode from 'vscode';
|
||||
import { log } from "./util";
|
||||
import { log } from './util';
|
||||
|
||||
export class PersistentState {
|
||||
constructor(private readonly ctx: vscode.ExtensionContext) {
|
||||
constructor(private readonly globalState: vscode.Memento) {
|
||||
const { lastCheck, releaseId, serverVersion } = this;
|
||||
log.debug("PersistentState: ", { lastCheck, releaseId, serverVersion });
|
||||
}
|
||||
|
||||
readonly installedNightlyExtensionReleaseDate = new DateStorage(
|
||||
"installed-nightly-extension-release-date",
|
||||
this.ctx.globalState
|
||||
);
|
||||
readonly serverReleaseDate = new DateStorage("server-release-date", this.ctx.globalState);
|
||||
readonly serverReleaseTag = new Storage<null | string>("server-release-tag", this.ctx.globalState, null);
|
||||
}
|
||||
|
||||
|
||||
export class Storage<T> {
|
||||
constructor(
|
||||
private readonly key: string,
|
||||
private readonly storage: vscode.Memento,
|
||||
private readonly defaultVal: T
|
||||
) { }
|
||||
|
||||
get(): T {
|
||||
const val = this.storage.get(this.key, this.defaultVal);
|
||||
log.debug(this.key, "==", val);
|
||||
return val;
|
||||
/**
|
||||
* Used to check for *nightly* updates once an hour.
|
||||
*/
|
||||
get lastCheck(): number | undefined {
|
||||
return this.globalState.get("lastCheck");
|
||||
}
|
||||
async set(val: T) {
|
||||
log.debug(this.key, "=", val);
|
||||
await this.storage.update(this.key, val);
|
||||
}
|
||||
}
|
||||
export class DateStorage {
|
||||
inner: Storage<null | string>;
|
||||
|
||||
constructor(key: string, storage: vscode.Memento) {
|
||||
this.inner = new Storage(key, storage, null);
|
||||
}
|
||||
|
||||
get(): null | Date {
|
||||
const dateStr = this.inner.get();
|
||||
return dateStr ? new Date(dateStr) : null;
|
||||
}
|
||||
|
||||
async set(date: null | Date) {
|
||||
await this.inner.set(date ? date.toString() : null);
|
||||
async updateLastCheck(value: number) {
|
||||
await this.globalState.update("lastCheck", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release id of the *nightly* extension.
|
||||
* Used to check if we should update.
|
||||
*/
|
||||
get releaseId(): number | undefined {
|
||||
return this.globalState.get("releaseId");
|
||||
}
|
||||
async updateReleaseId(value: number) {
|
||||
await this.globalState.update("releaseId", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Version of the extension that installed the server.
|
||||
* Used to check if we need to update the server.
|
||||
*/
|
||||
get serverVersion(): string | undefined {
|
||||
return this.globalState.get("serverVersion");
|
||||
}
|
||||
async updateServerVersion(value: string | undefined) {
|
||||
await this.globalState.update("serverVersion", value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue