@@ -29,7 +29,7 @@ import { isAwsError, ToolkitError } from '../../shared/errors'
2929import { telemetry } from '../../shared/telemetry/telemetry'
3030import { localize } from '../../shared/utilities/vsCodeUtils'
3131import { Commands } from '../../shared/vscode/commands2'
32- import { CachedResource } from '../../shared/utilities/resourceCache'
32+ import { CachedResource , GlobalStateSchema } from '../../shared/utilities/resourceCache'
3333
3434// TODO: is there a better way to manage all endpoint strings in one place?
3535export const defaultServiceConfig : CodeWhispererConfig = {
@@ -51,6 +51,10 @@ const endpoints = createConstantMap({
5151 */
5252export type ProfileSwitchIntent = 'user' | 'auth' | 'update' | 'reload'
5353
54+ interface RegionProfileGlobalState extends GlobalStateSchema < RegionProfile > {
55+ previousSelection : { [ label : string ] : RegionProfile }
56+ }
57+
5458export class RegionProfileManager {
5559 private static logger = getLogger ( )
5660 private _activeRegionProfile : RegionProfile | undefined
@@ -62,7 +66,7 @@ export class RegionProfileManager {
6266
6367 private readonly cache = new ( class extends CachedResource < RegionProfile [ ] > {
6468 constructor ( private readonly profileProvider : ( ) => Promise < RegionProfile [ ] > ) {
65- super ( 'aws.amazonq.regionProfiles.cache ' , 60000 , {
69+ super ( 'aws.amazonq.regionProfiles' , 60000 , {
6670 resource : {
6771 locked : false ,
6872 timestamp : 0 ,
@@ -293,13 +297,20 @@ export class RegionProfileManager {
293297 }
294298
295299 private loadPersistedRegionProfle ( ) : { [ label : string ] : RegionProfile } {
296- const previousPersistedState = globals . globalState . tryGet < { [ label : string ] : RegionProfile } > (
300+ const previousPersistedState = globals . globalState . tryGet < RegionProfileGlobalState > (
297301 'aws.amazonq.regionProfiles' ,
298302 Object ,
299- { }
303+ {
304+ previousSelection : { } ,
305+ resource : {
306+ locked : false ,
307+ result : undefined ,
308+ timestamp : 0 ,
309+ } ,
310+ }
300311 )
301312
302- return previousPersistedState
313+ return previousPersistedState . previousSelection
303314 }
304315
305316 async persistSelectRegionProfile ( ) {
@@ -311,13 +322,20 @@ export class RegionProfileManager {
311322 }
312323
313324 // persist connectionId to profileArn
314- const previousPersistedState = globals . globalState . tryGet < { [ label : string ] : RegionProfile } > (
325+ const previousPersistedState = globals . globalState . tryGet < RegionProfileGlobalState > (
315326 'aws.amazonq.regionProfiles' ,
316327 Object ,
317- { }
328+ {
329+ previousSelection : { } ,
330+ resource : {
331+ locked : false ,
332+ result : undefined ,
333+ timestamp : 0 ,
334+ } ,
335+ }
318336 )
319337
320- previousPersistedState [ conn . id ] = this . activeRegionProfile
338+ previousPersistedState . previousSelection [ conn . id ] = this . activeRegionProfile
321339 await globals . globalState . update ( 'aws.amazonq.regionProfiles' , previousPersistedState )
322340 }
323341
@@ -368,7 +386,23 @@ export class RegionProfileManager {
368386 const updatedProfiles = Object . fromEntries (
369387 Object . entries ( profiles ) . filter ( ( [ connId , profile ] ) => profile . arn !== arn )
370388 )
371- await globals . globalState . update ( 'aws.amazonq.regionProfiles' , updatedProfiles )
389+ const previousPersistedState = globals . globalState . tryGet < RegionProfileGlobalState > (
390+ 'aws.amazonq.regionProfiles' ,
391+ Object ,
392+ {
393+ previousSelection : { } ,
394+ resource : {
395+ locked : false ,
396+ result : undefined ,
397+ timestamp : 0 ,
398+ } ,
399+ }
400+ )
401+ const toUpdate : RegionProfileGlobalState = {
402+ previousSelection : updatedProfiles ,
403+ resource : previousPersistedState . resource ,
404+ }
405+ await globals . globalState . update ( 'aws.amazonq.regionProfiles' , toUpdate )
372406 }
373407 }
374408
0 commit comments