aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/config.ts
diff options
context:
space:
mode:
authorVeetaha <[email protected]>2020-03-09 18:28:12 +0000
committerVeetaha <[email protected]>2020-03-14 00:01:46 +0000
commitbc87d6de86a2d67febe7e4e21347af9c92dc7552 (patch)
tree458231252dabbd94e0817b8e1cc57bda57c9475b /editors/code/src/config.ts
parent77a206e0b2614c13d296b2c36affe5d21df38aee (diff)
vscode-postrefactor: global storages
Diffstat (limited to 'editors/code/src/config.ts')
-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 a05d8ac06..5371384ba 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -186,8 +186,8 @@ export class Config {
186 "rust-analyzer-server-release-date", 186 "rust-analyzer-server-release-date",
187 this.ctx.globalState 187 this.ctx.globalState
188 ); 188 );
189 readonly serverReleaseTag = new StringStorage( 189 readonly serverReleaseTag = new Storage<null | string>(
190 "rust-analyzer-release-tag", this.ctx.globalState 190 "rust-analyzer-release-tag", this.ctx.globalState, null
191 ); 191 );
192 192
193 // We don't do runtime config validation here for simplicity. More on stackoverflow: 193 // We don't do runtime config validation here for simplicity. More on stackoverflow:
@@ -234,37 +234,36 @@ export class Config {
234 get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; } 234 get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; }
235} 235}
236 236
237export class StringStorage { 237export class Storage<T> {
238 constructor( 238 constructor(
239 private readonly key: string, 239 private readonly key: string,
240 private readonly storage: vscode.Memento 240 private readonly storage: vscode.Memento,
241 private readonly defaultVal: T
241 ) { } 242 ) { }
242 243
243 get(): null | string { 244 get(): T {
244 const tag = this.storage.get(this.key, null); 245 const val = this.storage.get(this.key, this.defaultVal);
245 log.debug(this.key, "==", tag); 246 log.debug(this.key, "==", val);
246 return tag; 247 return val;
247 } 248 }
248 async set(tag: string) { 249 async set(val: T) {
249 log.debug(this.key, "=", tag); 250 log.debug(this.key, "=", val);
250 await this.storage.update(this.key, tag); 251 await this.storage.update(this.key, val);
251 } 252 }
252} 253}
253export class DateStorage { 254export class DateStorage {
255 inner: Storage<null | string>;
254 256
255 constructor( 257 constructor(key: string, storage: vscode.Memento) {
256 private readonly key: string, 258 this.inner = new Storage(key, storage, null);
257 private readonly storage: vscode.Memento 259 }
258 ) { }
259 260
260 get(): null | Date { 261 get(): null | Date {
261 const date = this.storage.get(this.key, null); 262 const dateStr = this.inner.get();
262 log.debug(this.key, "==", date); 263 return dateStr ? new Date(dateStr) : null;
263 return date ? new Date(date) : null;
264 } 264 }
265 265
266 async set(date: null | Date) { 266 async set(date: null | Date) {
267 log.debug(this.key, "=", date); 267 await this.inner.set(date ? date.toString() : null);
268 await this.storage.update(this.key, date);
269 } 268 }
270} 269}