Skip to content

Commit c024704

Browse files
committed
fix(core): Add globalState migration for CODEWHISPERER_PERSISTED_CUSTOMIZATIONS
1 parent b7fc59a commit c024704

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,15 @@ export const getPersistedCustomizations = (): Customization[] => {
139139
if (!AuthUtil.instance.isIdcConnection()) {
140140
return []
141141
}
142-
const persistedCustomizationsObj = globals.globalState.tryGet<{ [label: string]: Customization[] }>(
143-
'CODEWHISPERER_PERSISTED_CUSTOMIZATIONS',
144-
Object,
145-
{}
146-
)
147-
return persistedCustomizationsObj[AuthUtil.instance.profileName] || []
142+
return globals.globalState.getCodewhispererPersistedCustomization(AuthUtil.instance.profileName)
148143
}
149144

150145
export const setPersistedCustomizations = async (customizations: Customization[]) => {
151146
if (!AuthUtil.instance.isIdcConnection()) {
152147
return
153148
}
154-
const persistedCustomizationsObj = globals.globalState.tryGet<{ [label: string]: Customization[] }>(
155-
'CODEWHISPERER_PERSISTED_CUSTOMIZATIONS',
156-
Object,
157-
{}
158-
)
159-
persistedCustomizationsObj[AuthUtil.instance.profileName] = customizations
160-
await globals.globalState.update('CODEWHISPERER_PERSISTED_CUSTOMIZATIONS', persistedCustomizationsObj)
149+
150+
await globals.globalState.update('CODEWHISPERER_PERSISTED_CUSTOMIZATIONS', customizations)
161151
}
162152

163153
export const getNewCustomizationsAvailable = () => {

packages/core/src/shared/globalState.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export class GlobalState implements vscode.Memento {
229229
}
230230

231231
/**
232-
* Get the codewhisperer customerization. If legacy (map of customizations) store the
232+
* Get the codewhisperer customization. If legacy (map of customizations) store the
233233
* customization with label of profile name
234234
*
235235
* @param profileName name of profile, only used in case legacy customization is found
@@ -249,6 +249,32 @@ export class GlobalState implements vscode.Memento {
249249
}
250250
}
251251

252+
/**
253+
* Get the codewhisperer persisted customizations. If legacy (map of customizations) store the
254+
* customizations with label of profile name
255+
*
256+
* @param profileName name of profile, only used in case legacy customization is found
257+
* @returns array of codewhisperer persisted customizations, or empty array if not found.
258+
* If legacy, return the codewhisperer persisted customizations for the auth profile name
259+
*/
260+
getCodewhispererPersistedCCustomization(profileName: string): Customization[] {
261+
const result = this.tryGet<Customization[]>('CODEWHISPERER_PERSISTED_CUSTOMIZATIONS', Array, [])
262+
263+
// Legacy migration for old customization map of type { [label: string]: Customization[] }
264+
if (result.length === 0) {
265+
const customizations = this.tryGet<{ [label: string]: Customization[] }>(
266+
'CODEWHISPERER_PERSISTED_CUSTOMIZATIONS',
267+
Object,
268+
{}
269+
)
270+
const persistedCustomizationsArray = customizations[profileName] || []
271+
this.tryUpdate('CODEWHISPERER_PERSISTED_CUSTOMIZATIONS', persistedCustomizationsArray)
272+
return persistedCustomizationsArray
273+
} else {
274+
return result
275+
}
276+
}
277+
252278
/**
253279
* Sets SSO session creation timestamp for the given session `id`.
254280
*

0 commit comments

Comments
 (0)