about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorVeetaha <gerzoh1@gmail.com>2020-03-09 20:28:12 +0200
committerVeetaha <gerzoh1@gmail.com>2020-03-14 02:01:46 +0200
commitbc87d6de86a2d67febe7e4e21347af9c92dc7552 (patch)
tree458231252dabbd94e0817b8e1cc57bda57c9475b /editors/code/src
parent77a206e0b2614c13d296b2c36affe5d21df38aee (diff)
downloadrust-bc87d6de86a2d67febe7e4e21347af9c92dc7552.tar.gz
rust-bc87d6de86a2d67febe7e4e21347af9c92dc7552.zip
vscode-postrefactor: global storages
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/config.ts39
1 files changed, 19 insertions, 20 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index a05d8ac0679..5371384ba27 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -186,8 +186,8 @@ export class Config {
         "rust-analyzer-server-release-date",
         this.ctx.globalState
     );
-    readonly serverReleaseTag = new StringStorage(
-        "rust-analyzer-release-tag", this.ctx.globalState
+    readonly serverReleaseTag = new Storage<null | string>(
+        "rust-analyzer-release-tag", this.ctx.globalState, null
     );
 
     // We don't do runtime config validation here for simplicity. More on stackoverflow:
@@ -234,37 +234,36 @@ export class Config {
     get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; }
 }
 
-export class StringStorage {
+export class Storage<T> {
     constructor(
         private readonly key: string,
-        private readonly storage: vscode.Memento
+        private readonly storage: vscode.Memento,
+        private readonly defaultVal: T
     ) { }
 
-    get(): null | string {
-        const tag = this.storage.get(this.key, null);
-        log.debug(this.key, "==", tag);
-        return tag;
+    get(): T {
+        const val = this.storage.get(this.key, this.defaultVal);
+        log.debug(this.key, "==", val);
+        return val;
     }
-    async set(tag: string) {
-        log.debug(this.key, "=", tag);
-        await this.storage.update(this.key, tag);
+    async set(val: T) {
+        log.debug(this.key, "=", val);
+        await this.storage.update(this.key, val);
     }
 }
 export class DateStorage {
+    inner: Storage<null | string>;
 
-    constructor(
-        private readonly key: string,
-        private readonly storage: vscode.Memento
-    ) { }
+    constructor(key: string, storage: vscode.Memento) {
+        this.inner = new Storage(key, storage, null);
+    }
 
     get(): null | Date {
-        const date = this.storage.get(this.key, null);
-        log.debug(this.key, "==", date);
-        return date ? new Date(date) : null;
+        const dateStr = this.inner.get();
+        return dateStr ? new Date(dateStr) : null;
     }
 
     async set(date: null | Date) {
-        log.debug(this.key, "=", date);
-        await this.storage.update(this.key, date);
+        await this.inner.set(date ? date.toString() : null);
     }
 }