@@ -264,59 +264,6 @@ async function initializeAuth(client: LanguageClient): Promise<AmazonQLspAuth> {
264
264
return auth
265
265
}
266
266
267
- // jscpd:ignore-start
268
- async function initializeLanguageServerConfiguration ( client : LanguageClient , context : string = 'startup' ) {
269
- const logger = getLogger ( 'amazonqLsp' )
270
-
271
- if ( AuthUtil . instance . isConnectionValid ( ) ) {
272
- logger . info ( `[${ context } ] Initializing language server configuration` )
273
- // jscpd:ignore-end
274
-
275
- try {
276
- // Send profile configuration
277
- logger . debug ( `[${ context } ] Sending profile configuration to language server` )
278
- await sendProfileToLsp ( client )
279
- logger . debug ( `[${ context } ] Profile configuration sent successfully` )
280
-
281
- // Send customization configuration
282
- logger . debug ( `[${ context } ] Sending customization configuration to language server` )
283
- await pushConfigUpdate ( client , {
284
- type : 'customization' ,
285
- customization : getSelectedCustomization ( ) ,
286
- } )
287
- logger . debug ( `[${ context } ] Customization configuration sent successfully` )
288
-
289
- logger . info ( `[${ context } ] Language server configuration completed successfully` )
290
- } catch ( error ) {
291
- logger . error ( `[${ context } ] Failed to initialize language server configuration: ${ error } ` )
292
- throw error
293
- }
294
- } else {
295
- logger . warn (
296
- `[${ context } ] Connection invalid, skipping language server configuration - this will cause authentication failures`
297
- )
298
- const activeConnection = AuthUtil . instance . auth . activeConnection
299
- const connectionState = activeConnection
300
- ? AuthUtil . instance . auth . getConnectionState ( activeConnection )
301
- : 'no-connection'
302
- logger . warn ( `[${ context } ] Connection state: ${ connectionState } ` )
303
- }
304
- }
305
-
306
- async function sendProfileToLsp ( client : LanguageClient ) {
307
- const logger = getLogger ( 'amazonqLsp' )
308
- const profileArn = AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn
309
-
310
- logger . debug ( `Sending profile to LSP: ${ profileArn || 'undefined' } ` )
311
-
312
- await pushConfigUpdate ( client , {
313
- type : 'profile' ,
314
- profileArn : profileArn ,
315
- } )
316
-
317
- logger . debug ( `Profile sent to LSP successfully` )
318
- }
319
-
320
267
async function onLanguageServerReady (
321
268
extensionContext : vscode . ExtensionContext ,
322
269
auth : AmazonQLspAuth ,
@@ -348,7 +295,14 @@ async function onLanguageServerReady(
348
295
// We manually push the cached values the first time since event handlers, which should push, may not have been setup yet.
349
296
// Execution order is weird and should be fixed in the flare implementation.
350
297
// TODO: Revisit if we need this if we setup the event handlers properly
351
- await initializeLanguageServerConfiguration ( client , 'startup' )
298
+ if ( AuthUtil . instance . isConnectionValid ( ) ) {
299
+ await sendProfileToLsp ( client )
300
+
301
+ await pushConfigUpdate ( client , {
302
+ type : 'customization' ,
303
+ customization : getSelectedCustomization ( ) ,
304
+ } )
305
+ }
352
306
353
307
toDispose . push (
354
308
inlineManager ,
@@ -450,6 +404,13 @@ async function onLanguageServerReady(
450
404
// Set this inside onReady so that it only triggers on subsequent language server starts (not the first)
451
405
onServerRestartHandler ( client , auth )
452
406
)
407
+
408
+ async function sendProfileToLsp ( client : LanguageClient ) {
409
+ await pushConfigUpdate ( client , {
410
+ type : 'profile' ,
411
+ profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
412
+ } )
413
+ }
453
414
}
454
415
455
416
/**
@@ -469,21 +430,8 @@ function onServerRestartHandler(client: LanguageClient, auth: AmazonQLspAuth) {
469
430
// TODO: Port this metric override to common definitions
470
431
telemetry . languageServer_crash . emit ( { id : 'AmazonQ' } )
471
432
472
- const logger = getLogger ( 'amazonqLsp' )
473
- logger . info ( '[crash-recovery] Language server crash detected, reinitializing authentication' )
474
-
475
- try {
476
- // Send bearer token
477
- logger . debug ( '[crash-recovery] Refreshing connection and sending bearer token' )
478
- await auth . refreshConnection ( true )
479
- logger . debug ( '[crash-recovery] Bearer token sent successfully' )
480
-
481
- // Send profile and customization configuration
482
- await initializeLanguageServerConfiguration ( client , 'crash-recovery' )
483
- logger . info ( '[crash-recovery] Authentication reinitialized successfully' )
484
- } catch ( error ) {
485
- logger . error ( `[crash-recovery] Failed to reinitialize after crash: ${ error } ` )
486
- }
433
+ // Need to set the auth token in the again
434
+ await auth . refreshConnection ( true )
487
435
} )
488
436
}
489
437
0 commit comments