mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
vscode-postrefactor: global storages
This commit is contained in:
parent
77a206e0b2
commit
bc87d6de86
1 changed files with 19 additions and 20 deletions
|
@ -186,8 +186,8 @@ export class Config {
|
||||||
"rust-analyzer-server-release-date",
|
"rust-analyzer-server-release-date",
|
||||||
this.ctx.globalState
|
this.ctx.globalState
|
||||||
);
|
);
|
||||||
readonly serverReleaseTag = new StringStorage(
|
readonly serverReleaseTag = new Storage<null | string>(
|
||||||
"rust-analyzer-release-tag", this.ctx.globalState
|
"rust-analyzer-release-tag", this.ctx.globalState, null
|
||||||
);
|
);
|
||||||
|
|
||||||
// We don't do runtime config validation here for simplicity. More on stackoverflow:
|
// 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; }
|
get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; }
|
||||||
}
|
}
|
||||||
|
|
||||||
export class StringStorage {
|
export class Storage<T> {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly key: string,
|
private readonly key: string,
|
||||||
private readonly storage: vscode.Memento
|
private readonly storage: vscode.Memento,
|
||||||
|
private readonly defaultVal: T
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
get(): null | string {
|
get(): T {
|
||||||
const tag = this.storage.get(this.key, null);
|
const val = this.storage.get(this.key, this.defaultVal);
|
||||||
log.debug(this.key, "==", tag);
|
log.debug(this.key, "==", val);
|
||||||
return tag;
|
return val;
|
||||||
}
|
}
|
||||||
async set(tag: string) {
|
async set(val: T) {
|
||||||
log.debug(this.key, "=", tag);
|
log.debug(this.key, "=", val);
|
||||||
await this.storage.update(this.key, tag);
|
await this.storage.update(this.key, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class DateStorage {
|
export class DateStorage {
|
||||||
|
inner: Storage<null | string>;
|
||||||
|
|
||||||
constructor(
|
constructor(key: string, storage: vscode.Memento) {
|
||||||
private readonly key: string,
|
this.inner = new Storage(key, storage, null);
|
||||||
private readonly storage: vscode.Memento
|
}
|
||||||
) { }
|
|
||||||
|
|
||||||
get(): null | Date {
|
get(): null | Date {
|
||||||
const date = this.storage.get(this.key, null);
|
const dateStr = this.inner.get();
|
||||||
log.debug(this.key, "==", date);
|
return dateStr ? new Date(dateStr) : null;
|
||||||
return date ? new Date(date) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async set(date: null | Date) {
|
async set(date: null | Date) {
|
||||||
log.debug(this.key, "=", date);
|
await this.inner.set(date ? date.toString() : null);
|
||||||
await this.storage.update(this.key, date);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue