44 * -------------------------------------------------------------------------------------------- */
55'use strict' ;
66
7- export type LSSState = 'global' | 'workspace' ;
7+ export type LSSLoc = 'global' | 'workspace' ;
88
99import { ExtensionContext , Memento } from 'vscode' ;
10+ import { Logger } from './logger' ;
1011
1112export class LocalStorageService {
1213 private _wsState : Memento ;
@@ -17,19 +18,43 @@ export class LocalStorageService {
1718 this . _globalState = context . globalState ;
1819 }
1920
20- public getValue < T > ( key : string , loc : LSSState ) : T | undefined {
21+ public getValue < T > ( key : string , loc : LSSLoc ) : T | undefined {
2122 if ( loc === 'workspace' ) {
2223 return this . _wsState . get < T > ( key ) ;
2324 } else {
2425 return this . _globalState . get < T > ( key ) ;
2526 }
2627 }
2728
28- public async setValue < T > ( key : string , value : T , loc : LSSState ) {
29+ public async setValue < T > ( key : string , value : T , loc : LSSLoc ) : Promise < void > {
2930 if ( loc === 'workspace' ) {
30- await this . _wsState . update ( key , value ) ;
31+ try {
32+ await this . _wsState . update ( key , value ) ;
33+ } catch ( reason ) {
34+ Logger . error ( reason ) ;
35+ }
3136 } else {
32- await this . _globalState . update ( key , value ) ;
37+ try {
38+ await this . _globalState . update ( key , value ) ;
39+ } catch ( reason ) {
40+ Logger . error ( reason ) ;
41+ }
42+ }
43+ }
44+
45+ public async deleteValue ( key : string , loc : LSSLoc ) : Promise < void > {
46+ if ( loc === 'workspace' ) {
47+ try {
48+ await this . _wsState . update ( key , undefined ) ;
49+ } catch ( reason ) {
50+ Logger . error ( reason ) ;
51+ }
52+ } else {
53+ try {
54+ await this . _globalState . update ( key , undefined ) ;
55+ } catch ( reason ) {
56+ Logger . error ( reason ) ;
57+ }
3358 }
3459 }
3560}
0 commit comments