@@ -186,8 +186,8 @@ export class Config {
186
186
"rust-analyzer-server-release-date" ,
187
187
this . ctx . globalState
188
188
) ;
189
- readonly serverReleaseTag = new StringStorage (
190
- "rust-analyzer-release-tag" , this . ctx . globalState
189
+ readonly serverReleaseTag = new Storage < null | string > (
190
+ "rust-analyzer-release-tag" , this . ctx . globalState , null
191
191
) ;
192
192
193
193
// We don't do runtime config validation here for simplicity. More on stackoverflow:
@@ -234,37 +234,36 @@ export class Config {
234
234
get withSysroot ( ) { return this . cfg . get ( "withSysroot" , true ) as boolean ; }
235
235
}
236
236
237
- export class StringStorage {
237
+ export class Storage < T > {
238
238
constructor (
239
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
- const tag = this . storage . get ( this . key , null ) ;
245
- log . debug ( this . key , "==" , tag ) ;
246
- return tag ;
244
+ get ( ) : T {
245
+ const val = this . storage . get ( this . key , this . defaultVal ) ;
246
+ log . debug ( this . key , "==" , val ) ;
247
+ return val ;
247
248
}
248
- async set ( tag : string ) {
249
- log . debug ( this . key , "=" , tag ) ;
250
- await this . storage . update ( this . key , tag ) ;
249
+ async set ( val : T ) {
250
+ log . debug ( this . key , "=" , val ) ;
251
+ await this . storage . update ( this . key , val ) ;
251
252
}
252
253
}
253
254
export class DateStorage {
255
+ inner : Storage < null | string > ;
254
256
255
- constructor (
256
- private readonly key : string ,
257
- private readonly storage : vscode . Memento
258
- ) { }
257
+ constructor ( key : string , storage : vscode . Memento ) {
258
+ this . inner = new Storage ( key , storage , null ) ;
259
+ }
259
260
260
261
get ( ) : null | Date {
261
- const date = this . storage . get ( this . key , null ) ;
262
- log . debug ( this . key , "==" , date ) ;
263
- return date ? new Date ( date ) : null ;
262
+ const dateStr = this . inner . get ( ) ;
263
+ return dateStr ? new Date ( dateStr ) : null ;
264
264
}
265
265
266
266
async set ( date : null | Date ) {
267
- log . debug ( this . key , "=" , date ) ;
268
- await this . storage . update ( this . key , date ) ;
267
+ await this . inner . set ( date ? date . toString ( ) : null ) ;
269
268
}
270
269
}
0 commit comments