@@ -55,7 +55,7 @@ function handleRestart(conn: SsoConnection, ctx: ExtContext, envId: string | und
55
55
getLogger ( ) . info ( 'codecatalyst: attempting to poll dev environments' )
56
56
57
57
// Reconnect devenvs (if coming from a restart)
58
- reconnectDevEnvs ( conn , ctx ) . catch ( ( err ) => {
58
+ reconnectDevEnvs ( conn ) . catch ( ( err ) => {
59
59
getLogger ( ) . error ( `codecatalyst: error while resuming devenvs: ${ err } ` )
60
60
} )
61
61
}
@@ -66,9 +66,12 @@ function handleRestart(conn: SsoConnection, ctx: ExtContext, envId: string | und
66
66
* @param conn a connection that may be used for CodeCatalyst
67
67
* @param ctx the extension context
68
68
*/
69
- async function reconnectDevEnvs ( conn : SsoConnection , ctx : ExtContext ) : Promise < void > {
70
- const memento = ctx . extensionContext . globalState
71
- const pendingDevEnvs = memento . get < Record < string , DevEnvMemento > > ( 'CODECATALYST_RECONNECT' , { } )
69
+ async function reconnectDevEnvs ( conn : SsoConnection ) : Promise < void > {
70
+ const pendingDevEnvs = globals . globalState . tryGet < Record < string , DevEnvMemento > > (
71
+ 'CODECATALYST_RECONNECT' ,
72
+ Object ,
73
+ { }
74
+ )
72
75
const validDevEnvs = filterInvalidDevEnvs ( pendingDevEnvs )
73
76
if ( Object . keys ( validDevEnvs ) . length === 0 ) {
74
77
return
@@ -93,7 +96,7 @@ async function reconnectDevEnvs(conn: SsoConnection, ctx: ExtContext): Promise<v
93
96
progress . report ( { message : progressTitle } )
94
97
const client = await createClient ( conn )
95
98
96
- return pollDevEnvs ( client , progress , token , memento , validDevEnvs )
99
+ return pollDevEnvs ( client , progress , token , validDevEnvs )
97
100
}
98
101
)
99
102
}
@@ -115,14 +118,13 @@ function filterInvalidDevEnvs(devenvs: Record<string, DevEnvMemento>) {
115
118
/**
116
119
* Ensure that all devenvs that are currently being looked at set to attempting to reconnect so that they are not looked at
117
120
* by any other instance of VSCode.
118
- * @param memento
119
121
* @param devenvs
120
122
*/
121
- function setWatchedDevEnvStatus ( memento : vscode . Memento , devenvs : Record < string , DevEnvMemento > , watchStatus : boolean ) {
123
+ function setWatchedDevEnvStatus ( devenvs : Record < string , DevEnvMemento > , watchStatus : boolean ) {
122
124
for ( const [ id , detail ] of Object . entries ( devenvs ) ) {
123
125
devenvs [ id ] = { ...detail , attemptingReconnect : watchStatus }
124
126
}
125
- return memento . update ( 'CODECATALYST_RECONNECT' , devenvs )
127
+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , devenvs )
126
128
}
127
129
128
130
/**
@@ -131,26 +133,24 @@ function setWatchedDevEnvStatus(memento: vscode.Memento, devenvs: Record<string,
131
133
* 2. In a terminating state or expired, in which case no longer watch the devenv
132
134
* 3. Failed to start, in which case notify the user
133
135
* @param client A connected client
134
- * @param memento vscode global storage library
135
136
* @param devenvs All VALID devenvs that are not being watched by any other VSCode instance
136
137
*/
137
138
async function pollDevEnvs (
138
139
client : CodeCatalystClient ,
139
140
progress : vscode . Progress < { message : string } > ,
140
141
token : vscode . CancellationToken ,
141
- memento : vscode . Memento ,
142
142
devenvs : Record < string , DevEnvMemento >
143
143
) {
144
144
// Ensure that all devenvs that you want to look at are attempting reconnection
145
145
// and won't be watched by any other VSCode instance
146
- await setWatchedDevEnvStatus ( memento , devenvs , true )
146
+ await setWatchedDevEnvStatus ( devenvs , true )
147
147
148
148
const shouldCloseRootInstance = Object . keys ( devenvs ) . length === 1
149
149
getLogger ( ) . info ( `codecatalyst: reconnect: pollDevEnvs: ${ Object . keys ( devenvs ) . length } ` )
150
150
151
151
while ( Object . keys ( devenvs ) . length > 0 ) {
152
152
if ( token . isCancellationRequested ) {
153
- await setWatchedDevEnvStatus ( memento , devenvs , false )
153
+ await setWatchedDevEnvStatus ( devenvs , false )
154
154
return
155
155
}
156
156
@@ -197,7 +197,7 @@ async function pollDevEnvs(
197
197
progress . report ( { message : `Dev Environment ${ devenvName } has expired` } )
198
198
}
199
199
} catch {
200
- await failDevEnv ( memento , id )
200
+ await failDevEnv ( id )
201
201
delete devenvs [ id ]
202
202
void showViewLogsMessage (
203
203
localize ( 'AWS.codecatalyst.reconnect' , 'Unable to reconnect to ${0}' , devenvName )
@@ -220,14 +220,13 @@ function isExpired(previousConnectionTime: number): boolean {
220
220
}
221
221
222
222
/**
223
- * When a devenv fails, remove it from the memento so we no longer watch it in the future
224
- * @param memento The memento instance from vscode
223
+ * When a devenv fails, remove it from globalState so we no longer watch it in the future
225
224
* @param devenvId the id of the deveng to fail
226
225
*/
227
- function failDevEnv ( memento : vscode . Memento , devenvId : string ) {
228
- const curr = memento . get < Record < string , DevEnvMemento > > ( 'CODECATALYST_RECONNECT' , { } )
226
+ function failDevEnv ( devenvId : string ) {
227
+ const curr = globals . globalState . tryGet < Record < string , DevEnvMemento > > ( 'CODECATALYST_RECONNECT' , Object , { } )
229
228
delete curr [ devenvId ]
230
- return memento . update ( 'CODECATALYST_RECONNECT' , curr )
229
+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , curr )
231
230
}
232
231
233
232
async function openReconnectedDevEnv (
@@ -268,8 +267,11 @@ export function isLongReconnect(oldSettings: DevEnvironmentSettings, newSettings
268
267
}
269
268
270
269
export function saveReconnectionInformation ( devenv : DevEnvironmentId & Pick < DevEnvironment , 'alias' > ) : Thenable < void > {
271
- const memento = globals . context . globalState
272
- const pendingReconnects = memento . get < Record < string , DevEnvMemento > > ( 'CODECATALYST_RECONNECT' , { } )
270
+ const pendingReconnects = globals . globalState . tryGet < Record < string , DevEnvMemento > > (
271
+ 'CODECATALYST_RECONNECT' ,
272
+ Object ,
273
+ { }
274
+ )
273
275
const workspaceFolders = vscode . workspace . workspaceFolders
274
276
const currentWorkspace =
275
277
workspaceFolders !== undefined && workspaceFolders . length > 0 ? workspaceFolders [ 0 ] . uri . fsPath : '/projects'
@@ -281,12 +283,15 @@ export function saveReconnectionInformation(devenv: DevEnvironmentId & Pick<DevE
281
283
previousConnectionTimestamp : Date . now ( ) ,
282
284
alias : devenv . alias ,
283
285
}
284
- return memento . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
286
+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
285
287
}
286
288
287
289
export function removeReconnectionInformation ( devenv : DevEnvironmentId ) : Thenable < void > {
288
- const memento = globals . context . globalState
289
- const pendingReconnects = memento . get < Record < string , DevEnvMemento > > ( 'CODECATALYST_RECONNECT' , { } )
290
+ const pendingReconnects = globals . globalState . tryGet < Record < string , DevEnvMemento > > (
291
+ 'CODECATALYST_RECONNECT' ,
292
+ Object ,
293
+ { }
294
+ )
290
295
delete pendingReconnects [ devenv . id ]
291
- return memento . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
296
+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
292
297
}
0 commit comments