aboutsummaryrefslogtreecommitdiff
path: root/editors/vscode/src/persistent_state.ts
blob: ecab10c1a6372ff246b9b3b75bf3a6fabdb120b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as vscode from 'vscode';
import { log } from './util';

//modified from https://github.com/rust-analyzer/rust-analyzer/blob/master/editors/code/src/persistent_state.ts - 03.05.2021

export class PersistentState {
    constructor(private readonly globalState: vscode.Memento) {
        const { lastCheck, releaseId, serverVersion } = this;
        log.info("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);
    }

    /**
     * Github authorization token.
     * This is used for API requests against the Github API.
     */
    get githubToken(): string | undefined {
        return this.globalState.get("githubToken");
    }
    async updateGithubToken(value: string | undefined) {
        await this.globalState.update("githubToken", value);
    }
}