@@ -197,6 +197,11 @@ export async function checkOrInstallAppModExtensionForUpgrade(
197197 }
198198
199199 await commands . executeCommand ( "workbench.extensions.installExtension" , ExtensionName . APP_MODERNIZATION_FOR_JAVA ) ;
200+ sendInfo ( operationId , {
201+ operationName : "java.dependency.upgradeFlow.result" ,
202+ upgradeFlowStep : "installSucceeded" ,
203+ installType : state === "outdated" ? "updated" : "installed" ,
204+ } ) ;
200205
201206 if ( state === "outdated" ) {
202207 // Extension was updated (not freshly installed) — reload required
@@ -219,18 +224,35 @@ export async function checkOrInstallAppModExtensionForUpgrade(
219224 return false ;
220225 }
221226
222- await checkOrPromptToEnableAppModExtension ( "upgrade" ) ;
227+ // Wait until the freshly installed extension is registered, returning as
228+ // soon as it is ready, or after a 5s timeout fallback at the latest.
229+ await waitForExtensionReady ( extensionIdToCheck , 5000 ) ;
223230
224- // Wait briefly for the newly installed extension to activate
225- await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
226-
227- // Re-check if the newly installed extension is active and meets version requirement
228- const newState = getExtensionState ( extensionIdToCheck ) ;
229- const canProceed = newState === "up-to-date" ;
230231 sendInfo ( operationId , {
231232 operationName : "java.dependency.upgradeFlow.result" ,
232- upgradeFlowResult : canProceed ? "proceeded" : "activation-timeout ",
233+ upgradeFlowResult : "proceeded" ,
233234 } ) ;
234- return canProceed ;
235+ return true ;
235236 } ) ( ) ;
236- }
237+ }
238+
239+ function waitForExtensionReady ( extensionId : string , timeoutMs : number ) : Promise < void > {
240+ return new Promise < void > ( resolve => {
241+ if ( extensions . getExtension ( extensionId ) ) {
242+ resolve ( ) ;
243+ return ;
244+ }
245+ let timer : NodeJS . Timeout ;
246+ const disposable = extensions . onDidChange ( ( ) => {
247+ if ( extensions . getExtension ( extensionId ) ) {
248+ clearTimeout ( timer ) ;
249+ disposable . dispose ( ) ;
250+ resolve ( ) ;
251+ }
252+ } ) ;
253+ timer = setTimeout ( ( ) => {
254+ disposable . dispose ( ) ;
255+ resolve ( ) ;
256+ } , timeoutMs ) ;
257+ } ) ;
258+ }
0 commit comments