@@ -22,7 +22,7 @@ export const toggleCodeSuggestions = Commands.declare(
22
22
'aws.codeWhisperer.toggleCodeSuggestion' ,
23
23
( context : ExtContext ) => async ( ) => {
24
24
const autoTriggerEnabled : boolean = get ( CodeWhispererConstants . autoTriggerEnabledKey , context ) || false
25
- set ( CodeWhispererConstants . autoTriggerEnabledKey , ! autoTriggerEnabled , context )
25
+ await set ( CodeWhispererConstants . autoTriggerEnabledKey , ! autoTriggerEnabled , context )
26
26
await vscode . commands . executeCommand ( 'aws.codeWhisperer.refresh' )
27
27
}
28
28
)
@@ -45,7 +45,11 @@ export const enterAccessToken = Commands.declare(
45
45
'aws.codeWhisperer.enterAccessToken' ,
46
46
( context : ExtContext , client : DefaultCodeWhispererClient ) => async ( ) => {
47
47
const setToken = async ( token : string ) => {
48
- set ( CodeWhispererConstants . accessToken , token , context )
48
+ try {
49
+ await context . extensionContext . globalState . update ( CodeWhispererConstants . accessToken , token )
50
+ } catch ( error ) {
51
+ getLogger ( ) . error ( `Failed to save access token: ${ error } ` )
52
+ }
49
53
await vscode . commands . executeCommand ( 'aws.codeWhisperer.refresh' )
50
54
await vscode . commands . executeCommand ( 'aws.codeWhisperer.enableCodeSuggestions' )
51
55
}
@@ -66,10 +70,10 @@ export const requestAccessCloud9 = Commands.declare(
66
70
try {
67
71
await vscode . commands . executeCommand ( 'cloud9.codeWhispererRequestAccess' )
68
72
showTimedMessage ( CodeWhispererConstants . cloud9AccessSent , 3000 )
69
- set ( CodeWhispererConstants . cloud9AccessStateKey , Cloud9AccessState . RequestedAccess , context )
73
+ await set ( CodeWhispererConstants . cloud9AccessStateKey , Cloud9AccessState . RequestedAccess , context )
70
74
} catch ( e ) {
71
75
getLogger ( ) . error ( `Encountered error when requesting cloud9 access ${ e } ` )
72
- set ( CodeWhispererConstants . cloud9AccessStateKey , Cloud9AccessState . NoAccess , context )
76
+ await set ( CodeWhispererConstants . cloud9AccessStateKey , Cloud9AccessState . NoAccess , context )
73
77
}
74
78
}
75
79
}
@@ -109,7 +113,7 @@ export const updateCloud9TreeNodes = Commands.declare(
109
113
for ( let i = 0 ; i < 3 ; i ++ ) {
110
114
const result = await testApiCall ( )
111
115
if ( result ) {
112
- context . extensionContext . globalState . update (
116
+ await context . extensionContext . globalState . update (
113
117
CodeWhispererConstants . cloud9AccessStateKey ,
114
118
Cloud9AccessState . HasAccess
115
119
)
@@ -119,14 +123,14 @@ export const updateCloud9TreeNodes = Commands.declare(
119
123
sleep ( 1000 )
120
124
}
121
125
if ( state !== Cloud9AccessState . RequestedAccess ) {
122
- context . extensionContext . globalState . update (
126
+ await context . extensionContext . globalState . update (
123
127
CodeWhispererConstants . cloud9AccessStateKey ,
124
128
Cloud9AccessState . NoAccess
125
129
)
126
130
}
127
131
} catch ( e ) {
128
132
getLogger ( ) . error ( `Error when updateCloud9TreeNodes ${ e } ` )
129
- context . extensionContext . globalState . update (
133
+ await context . extensionContext . globalState . update (
130
134
CodeWhispererConstants . cloud9AccessStateKey ,
131
135
Cloud9AccessState . NoAccess
132
136
)
@@ -163,8 +167,8 @@ export function get(key: string, context: ExtContext): any {
163
167
return context . extensionContext . globalState . get ( key )
164
168
}
165
169
166
- export function set ( key : string , value : any , context : ExtContext ) : void {
167
- context . extensionContext . globalState . update ( key , value ) . then (
170
+ export async function set ( key : string , value : any , context : ExtContext ) : Promise < void > {
171
+ await context . extensionContext . globalState . update ( key , value ) . then (
168
172
( ) => { } ,
169
173
error => {
170
174
getLogger ( ) . verbose ( `Failed to update global state: ${ error } ` )
0 commit comments