Skip to content

Commit b7fc59a

Browse files
committed
fix(core): add migration for codewhisperer selected customization global state
1 parent fa57ed1 commit b7fc59a

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

packages/core/src/codewhisperer/util/customizationUtil.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ export const getSelectedCustomization = (): Customization => {
9898
return baseCustomization
9999
}
100100

101-
const selectedCustomization = globals.globalState.tryGet<Customization>(
102-
'CODEWHISPERER_SELECTED_CUSTOMIZATION',
103-
Object
104-
)
101+
const selectedCustomization = globals.globalState.getCodewhispererCustomization(AuthUtil.instance.profileName)
105102

106103
if (selectedCustomization && selectedCustomization.name !== '') {
107104
return selectedCustomization

packages/core/src/shared/globalState.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as vscode from 'vscode'
77
import { getLogger } from './logger/logger'
88
import * as redshift from '../awsService/redshift/models/models'
99
import { TypeConstructor, cast } from './utilities/typeConstructors'
10+
import { Customization } from '../codewhisperer/client/codewhispereruserclient'
1011

1112
type ToolId = 'codecatalyst' | 'codewhisperer' | 'testId'
1213
export type ToolIdStateKey = `${ToolId}.savedConnectionId`
@@ -227,6 +228,27 @@ export class GlobalState implements vscode.Memento {
227228
return all?.[warehouseArn]
228229
}
229230

231+
/**
232+
* Get the codewhisperer customerization. If legacy (map of customizations) store the
233+
* customization with label of profile name
234+
*
235+
* @param profileName name of profile, only used in case legacy customization is found
236+
* @returns codewhisperer customization, or undefined if not found.
237+
* If legacy, return the codewhisperer customization for the auth profile name
238+
*/
239+
getCodewhispererCustomization(profileName: string): Customization | undefined {
240+
const result = this.tryGet('CODEWHISPERER_SELECTED_CUSTOMIZATION', Object, undefined)
241+
242+
// Legacy migration for old customization map of type { [label: string]: Customization[] }
243+
if (typeof result === 'object' && Object.values(result).every(Array.isArray)) {
244+
const selectedCustomization = result[profileName]
245+
this.tryUpdate('CODEWHISPERER_SELECTED_CUSTOMIZATION', selectedCustomization)
246+
return selectedCustomization
247+
} else {
248+
return result
249+
}
250+
}
251+
230252
/**
231253
* Sets SSO session creation timestamp for the given session `id`.
232254
*

0 commit comments

Comments
 (0)