@@ -55,7 +55,7 @@ function handleRestart(conn: SsoConnection, ctx: ExtContext, envId: string | und
5555 getLogger ( ) . info ( 'codecatalyst: attempting to poll dev environments' )
5656
5757 // Reconnect devenvs (if coming from a restart)
58- reconnectDevEnvs ( conn , ctx ) . catch ( ( err ) => {
58+ reconnectDevEnvs ( conn ) . catch ( ( err ) => {
5959 getLogger ( ) . error ( `codecatalyst: error while resuming devenvs: ${ err } ` )
6060 } )
6161 }
@@ -66,9 +66,12 @@ function handleRestart(conn: SsoConnection, ctx: ExtContext, envId: string | und
6666 * @param conn a connection that may be used for CodeCatalyst
6767 * @param ctx the extension context
6868 */
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+ )
7275 const validDevEnvs = filterInvalidDevEnvs ( pendingDevEnvs )
7376 if ( Object . keys ( validDevEnvs ) . length === 0 ) {
7477 return
@@ -93,7 +96,7 @@ async function reconnectDevEnvs(conn: SsoConnection, ctx: ExtContext): Promise<v
9396 progress . report ( { message : progressTitle } )
9497 const client = await createClient ( conn )
9598
96- return pollDevEnvs ( client , progress , token , memento , validDevEnvs )
99+ return pollDevEnvs ( client , progress , token , validDevEnvs )
97100 }
98101 )
99102}
@@ -115,14 +118,13 @@ function filterInvalidDevEnvs(devenvs: Record<string, DevEnvMemento>) {
115118/**
116119 * Ensure that all devenvs that are currently being looked at set to attempting to reconnect so that they are not looked at
117120 * by any other instance of VSCode.
118- * @param memento
119121 * @param devenvs
120122 */
121- function setWatchedDevEnvStatus ( memento : vscode . Memento , devenvs : Record < string , DevEnvMemento > , watchStatus : boolean ) {
123+ function setWatchedDevEnvStatus ( devenvs : Record < string , DevEnvMemento > , watchStatus : boolean ) {
122124 for ( const [ id , detail ] of Object . entries ( devenvs ) ) {
123125 devenvs [ id ] = { ...detail , attemptingReconnect : watchStatus }
124126 }
125- return memento . update ( 'CODECATALYST_RECONNECT' , devenvs )
127+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , devenvs )
126128}
127129
128130/**
@@ -131,26 +133,24 @@ function setWatchedDevEnvStatus(memento: vscode.Memento, devenvs: Record<string,
131133 * 2. In a terminating state or expired, in which case no longer watch the devenv
132134 * 3. Failed to start, in which case notify the user
133135 * @param client A connected client
134- * @param memento vscode global storage library
135136 * @param devenvs All VALID devenvs that are not being watched by any other VSCode instance
136137 */
137138async function pollDevEnvs (
138139 client : CodeCatalystClient ,
139140 progress : vscode . Progress < { message : string } > ,
140141 token : vscode . CancellationToken ,
141- memento : vscode . Memento ,
142142 devenvs : Record < string , DevEnvMemento >
143143) {
144144 // Ensure that all devenvs that you want to look at are attempting reconnection
145145 // and won't be watched by any other VSCode instance
146- await setWatchedDevEnvStatus ( memento , devenvs , true )
146+ await setWatchedDevEnvStatus ( devenvs , true )
147147
148148 const shouldCloseRootInstance = Object . keys ( devenvs ) . length === 1
149149 getLogger ( ) . info ( `codecatalyst: reconnect: pollDevEnvs: ${ Object . keys ( devenvs ) . length } ` )
150150
151151 while ( Object . keys ( devenvs ) . length > 0 ) {
152152 if ( token . isCancellationRequested ) {
153- await setWatchedDevEnvStatus ( memento , devenvs , false )
153+ await setWatchedDevEnvStatus ( devenvs , false )
154154 return
155155 }
156156
@@ -197,7 +197,7 @@ async function pollDevEnvs(
197197 progress . report ( { message : `Dev Environment ${ devenvName } has expired` } )
198198 }
199199 } catch {
200- await failDevEnv ( memento , id )
200+ await failDevEnv ( id )
201201 delete devenvs [ id ]
202202 void showViewLogsMessage (
203203 localize ( 'AWS.codecatalyst.reconnect' , 'Unable to reconnect to ${0}' , devenvName )
@@ -220,14 +220,13 @@ function isExpired(previousConnectionTime: number): boolean {
220220}
221221
222222/**
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
225224 * @param devenvId the id of the deveng to fail
226225 */
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 , { } )
229228 delete curr [ devenvId ]
230- return memento . update ( 'CODECATALYST_RECONNECT' , curr )
229+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , curr )
231230}
232231
233232async function openReconnectedDevEnv (
@@ -268,8 +267,11 @@ export function isLongReconnect(oldSettings: DevEnvironmentSettings, newSettings
268267}
269268
270269export 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+ )
273275 const workspaceFolders = vscode . workspace . workspaceFolders
274276 const currentWorkspace =
275277 workspaceFolders !== undefined && workspaceFolders . length > 0 ? workspaceFolders [ 0 ] . uri . fsPath : '/projects'
@@ -281,12 +283,15 @@ export function saveReconnectionInformation(devenv: DevEnvironmentId & Pick<DevE
281283 previousConnectionTimestamp : Date . now ( ) ,
282284 alias : devenv . alias ,
283285 }
284- return memento . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
286+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
285287}
286288
287289export 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+ )
290295 delete pendingReconnects [ devenv . id ]
291- return memento . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
296+ return globals . globalState . update ( 'CODECATALYST_RECONNECT' , pendingReconnects )
292297}
0 commit comments