rust-analyzer/editors/code/src/persistent_state.ts
Aleksey Kladov fb6e655de8 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).
2020-03-19 09:04:59 +01:00

41 lines
1.2 KiB
TypeScript

import * as vscode from 'vscode';
import { log } from './util';
export class PersistentState {
constructor(private readonly globalState: vscode.Memento) {
const { lastCheck, releaseId, serverVersion } = this;
log.debug("PersistentState: ", { lastCheck, releaseId, serverVersion });
}
/**
* Used to check for *nightly* updates once an hour.
*/
get lastCheck(): number | undefined {
return this.globalState.get("lastCheck");
}
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);
}
}