@@ -31,6 +31,7 @@ export class PersistentState<T> implements IPersistentState<T> {
3131 this . key ,
3232 { data : this . defaultValue ! } ,
3333 ) ;
34+
3435 if (
3536 ! cachedData ||
3637 ! cachedData . expiry ||
@@ -69,6 +70,7 @@ export class PersistentState<T> implements IPersistentState<T> {
6970 ) ;
7071 await this . updateValue ( undefined as any , false ) ;
7172 await this . updateValue ( newValue , false ) ;
73+
7274 if ( JSON . stringify ( this . value ) !== JSON . stringify ( newValue ) ) {
7375 traceWarn (
7476 "Retry failed, storage update failed for key" ,
@@ -88,6 +90,7 @@ export const WORKSPACE_PERSISTENT_KEYS_DEPRECATED =
8890 "PYTHON_EXTENSION_WORKSPACE_STORAGE_KEYS" ;
8991
9092const GLOBAL_PERSISTENT_KEYS = "PYTHON_GLOBAL_STORAGE_KEYS" ;
93+
9194const WORKSPACE_PERSISTENT_KEYS = "PYTHON_WORKSPACE_STORAGE_KEYS" ;
9295type KeysStorageType = "global" | "workspace" ;
9396export type KeysStorage = { key : string ; defaultValue : unknown } ;
@@ -123,10 +126,12 @@ export class PersistentStateFactory implements IPersistentStateFactory {
123126 Commands . ClearStorage ,
124127 this . cleanAllPersistentStates . bind ( this ) ,
125128 ) ;
129+
126130 const globalKeysStorageDeprecated = this . createGlobalPersistentState (
127131 GLOBAL_PERSISTENT_KEYS_DEPRECATED ,
128132 [ ] ,
129133 ) ;
134+
130135 const workspaceKeysStorageDeprecated =
131136 this . createWorkspacePersistentState (
132137 WORKSPACE_PERSISTENT_KEYS_DEPRECATED ,
@@ -148,6 +153,7 @@ export class PersistentStateFactory implements IPersistentStateFactory {
148153 expiryDurationMs ?: number ,
149154 ) : IPersistentState < T > {
150155 ignoreErrors ( this . addKeyToStorage ( "global" , key , defaultValue ) ) ;
156+
151157 return new PersistentState < T > (
152158 this . globalState ,
153159 key ,
@@ -162,6 +168,7 @@ export class PersistentStateFactory implements IPersistentStateFactory {
162168 expiryDurationMs ?: number ,
163169 ) : IPersistentState < T > {
164170 ignoreErrors ( this . addKeyToStorage ( "workspace" , key , defaultValue ) ) ;
171+
165172 return new PersistentState < T > (
166173 this . workspaceState ,
167174 key ,
@@ -184,7 +191,9 @@ export class PersistentStateFactory implements IPersistentStateFactory {
184191 keyStorageType === "global"
185192 ? this . _globalKeysStorage
186193 : this . _workspaceKeysStorage ;
194+
187195 const found = storage . value . find ( ( value ) => value . key === key ) ;
196+
188197 if ( ! found ) {
189198 await storage . updateValue ( [
190199 { key, defaultValue } ,
@@ -222,6 +231,7 @@ export class PersistentStateFactory implements IPersistentStateFactory {
222231
223232export interface IPersistentStorage < T > {
224233 get ( ) : T ;
234+
225235 set ( value : T ) : Promise < void > ;
226236}
227237
@@ -238,14 +248,17 @@ export function getGlobalStorage<T>(
238248 GLOBAL_PERSISTENT_KEYS ,
239249 [ ] ,
240250 ) ;
251+
241252 const found = globalKeysStorage . value . find (
242253 ( value ) => value . key === key && value . defaultValue === defaultValue ,
243254 ) ;
255+
244256 if ( ! found ) {
245257 const newValue = [ { key, defaultValue } , ...globalKeysStorage . value ] ;
246258 ignoreErrors ( globalKeysStorage . updateValue ( newValue ) ) ;
247259 }
248260 const raw = new PersistentState < T > ( context . globalState , key , defaultValue ) ;
261+
249262 return {
250263 // We adapt between PersistentState and IPersistentStorage.
251264 get ( ) {
0 commit comments