4
4
*/
5
5
6
6
import globals from '../../shared/extensionGlobals'
7
- import {
8
- customLearnMoreUri ,
9
- newCustomizationsAvailableKey ,
10
- newCustomizationMessage ,
11
- persistedCustomizationsKey ,
12
- selectedCustomizationKey ,
13
- } from '../models/constants'
7
+ import { customLearnMoreUri , newCustomizationMessage } from '../models/constants'
14
8
import { localize , openUrl } from '../../shared/utilities/vsCodeUtils'
15
9
import { AuthUtil } from './authUtil'
16
- import { set } from './commonUtil'
17
10
import * as vscode from 'vscode'
18
11
import { createCommonButtons } from '../../shared/ui/buttons'
19
12
import { DataQuickPickItem , showQuickPick } from '../../shared/ui/pickerPrompter'
@@ -107,8 +100,11 @@ export const getSelectedCustomization = (): Customization => {
107
100
return baseCustomization
108
101
}
109
102
110
- const selectedCustomizationArr =
111
- globals . context . globalState . get < { [ label : string ] : Customization } > ( selectedCustomizationKey ) || { }
103
+ const selectedCustomizationArr = globals . globalState . tryGet < { [ label : string ] : Customization } > (
104
+ 'CODEWHISPERER_SELECTED_CUSTOMIZATION' ,
105
+ Object ,
106
+ { }
107
+ )
112
108
const result = selectedCustomizationArr [ AuthUtil . instance . conn . label ] || baseCustomization
113
109
114
110
// A/B case
@@ -130,12 +126,15 @@ export const setSelectedCustomization = async (customization: Customization) =>
130
126
if ( ! AuthUtil . instance . isValidEnterpriseSsoInUse ( ) || ! AuthUtil . instance . conn ) {
131
127
return
132
128
}
133
- const selectedCustomizationObj =
134
- globals . context . globalState . get < { [ label : string ] : Customization } > ( selectedCustomizationKey ) || { }
129
+ const selectedCustomizationObj = globals . globalState . tryGet < { [ label : string ] : Customization } > (
130
+ 'CODEWHISPERER_SELECTED_CUSTOMIZATION' ,
131
+ Object ,
132
+ { }
133
+ )
135
134
selectedCustomizationObj [ AuthUtil . instance . conn . label ] = customization
136
135
getLogger ( ) . debug ( `Selected customization ${ customization . name } for ${ AuthUtil . instance . conn . label } ` )
137
136
138
- await set ( selectedCustomizationKey , selectedCustomizationObj , globals . context . globalState )
137
+ await globals . globalState . tryUpdate ( 'CODEWHISPERER_SELECTED_CUSTOMIZATION' , selectedCustomizationObj )
139
138
vsCodeState . isFreeTierLimitReached = false
140
139
await Commands . tryExecute ( 'aws.amazonq.refreshStatusBar' )
141
140
}
@@ -144,27 +143,33 @@ export const getPersistedCustomizations = (): Customization[] => {
144
143
if ( ! AuthUtil . instance . isValidEnterpriseSsoInUse ( ) || ! AuthUtil . instance . conn ) {
145
144
return [ ]
146
145
}
147
- const persistedCustomizationsObj =
148
- globals . context . globalState . get < { [ label : string ] : Customization [ ] } > ( persistedCustomizationsKey ) || { }
146
+ const persistedCustomizationsObj = globals . globalState . tryGet < { [ label : string ] : Customization [ ] } > (
147
+ 'CODEWHISPERER_PERSISTED_CUSTOMIZATIONS' ,
148
+ Object ,
149
+ { }
150
+ )
149
151
return persistedCustomizationsObj [ AuthUtil . instance . conn . label ] || [ ]
150
152
}
151
153
152
154
export const setPersistedCustomizations = async ( customizations : Customization [ ] ) => {
153
155
if ( ! AuthUtil . instance . isValidEnterpriseSsoInUse ( ) || ! AuthUtil . instance . conn ) {
154
156
return
155
157
}
156
- const persistedCustomizationsObj =
157
- globals . context . globalState . get < { [ label : string ] : Customization [ ] } > ( persistedCustomizationsKey ) || { }
158
+ const persistedCustomizationsObj = globals . globalState . tryGet < { [ label : string ] : Customization [ ] } > (
159
+ 'CODEWHISPERER_PERSISTED_CUSTOMIZATIONS' ,
160
+ Object ,
161
+ { }
162
+ )
158
163
persistedCustomizationsObj [ AuthUtil . instance . conn . label ] = customizations
159
- await set ( persistedCustomizationsKey , persistedCustomizationsObj , globals . context . globalState )
164
+ await globals . globalState . tryUpdate ( 'CODEWHISPERER_PERSISTED_CUSTOMIZATIONS' , persistedCustomizationsObj )
160
165
}
161
166
162
167
export const getNewCustomizationsAvailable = ( ) => {
163
- return globals . context . globalState . get < number > ( newCustomizationsAvailableKey ) ?? 0
168
+ return globals . globalState . tryGet ( 'aws.amazonq.codewhisperer.newCustomizations' , Number , 0 )
164
169
}
165
170
166
171
export const setNewCustomizationsAvailable = async ( num : number ) => {
167
- await set ( newCustomizationsAvailableKey , num , globals . context . globalState )
172
+ await globals . globalState . tryUpdate ( 'aws.amazonq.codewhisperer.newCustomizations' , num )
168
173
vsCodeState . isFreeTierLimitReached = false
169
174
}
170
175
0 commit comments