@@ -30,7 +30,6 @@ import {
3030 ShowDocumentResult ,
3131 ResponseError ,
3232 LSPErrorCodes ,
33- updateConfigurationRequestType ,
3433} from '@aws/language-server-runtimes/protocol'
3534import {
3635 AuthUtil ,
@@ -187,13 +186,13 @@ export async function startLanguageServer(
187186 *
188187 * All other LSP initialization steps should happen after this.
189188 */
190- await initializeAuth ( client )
189+ await initializeAuth ( client , toDispose )
191190
192191 await postStartLanguageServer ( client , resourcePaths , toDispose )
193192
194193 return client
195194
196- async function initializeAuth ( client : LanguageClient ) {
195+ async function initializeAuth ( client : LanguageClient , toDispose : vscode . Disposable [ ] ) {
197196 AuthUtil . create ( new auth2 . LanguageClientAuth ( client , clientId , encryptionKey ) )
198197
199198 // Migrate SSO connections from old Auth to the LSP identity server
@@ -205,15 +204,17 @@ export async function startLanguageServer(
205204 getLogger ( ) . error ( `Error while migration SSO connection to Amazon Q LSP: ${ e } ` )
206205 }
207206
208- // Push region profile to the Q Language Server whenever it changes
209- AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( async ( ) => {
210- void pushConfigUpdate ( client , {
211- type : 'profile' ,
212- profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
207+ // We set these handlers before the auth restore below since it may trigger these
208+ toDispose . push (
209+ // Push region profile to the Q Language Server whenever it changes
210+ AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( async ( ) => {
211+ await sendDeveloperProfileToLsp ( client )
212+ } ) ,
213+ // Handle for Customization when the Developer Profile changes
214+ AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( ( e ) => {
215+ onProfileChangedListener ( e )
213216 } )
214- } )
215- // Handle for Customization when the Developer Profile changes
216- AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( onProfileChangedListener )
217+ )
217218
218219 // THIS SHOULD BE LAST!!!
219220 // This will result start the process of initializing the cached token (if it exists)
@@ -268,23 +269,6 @@ async function postStartLanguageServer(
268269 }
269270 )
270271
271- const sendProfileToLsp = async ( ) => {
272- try {
273- const result = await client . sendRequest ( updateConfigurationRequestType . method , {
274- section : 'aws.q' ,
275- settings : {
276- profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
277- } ,
278- } )
279- client . info (
280- `Client: Updated Amazon Q Profile ${ AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn } to Amazon Q LSP` ,
281- result
282- )
283- } catch ( err ) {
284- client . error ( 'Error when setting Q Developer Profile to Amazon Q LSP' , err )
285- }
286- }
287-
288272 let promise : Promise < void > | undefined
289273 let resolver : ( ) => void = ( ) => { }
290274 client . onProgress ( GetSsoTokenProgressType , GetSsoTokenProgressToken , async ( partialResult : GetSsoTokenProgress ) => {
@@ -305,7 +289,7 @@ async function postStartLanguageServer(
305289 }
306290
307291 // send profile to lsp once.
308- void sendProfileToLsp ( )
292+ void sendDeveloperProfileToLsp ( client )
309293
310294 void vscode . window . withProgress (
311295 {
@@ -337,7 +321,6 @@ async function postStartLanguageServer(
337321 }
338322
339323 toDispose . push (
340- AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( sendProfileToLsp ) ,
341324 vscode . commands . registerCommand ( 'aws.amazonq.getWorkspaceId' , async ( ) => {
342325 const requestType = new RequestType < GetConfigurationFromServerParams , ResponseMessage , Error > (
343326 'aws/getConfigurationFromServer'
@@ -398,6 +381,20 @@ async function postStartLanguageServer(
398381 )
399382}
400383
384+ async function sendDeveloperProfileToLsp ( client : LanguageClient ) {
385+ const profileArn = AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn
386+
387+ try {
388+ await pushConfigUpdate ( client , {
389+ type : 'profile' ,
390+ profileArn,
391+ } )
392+ client . info ( `DeveloperProfile: Successfully pushed Developer Profile, ${ profileArn } , to Amazon Q LSP` )
393+ } catch ( err ) {
394+ client . error ( `DeveloperProfile: Failed to push Developer Profile, ${ profileArn } , to Amazon Q LSP` , err )
395+ }
396+ }
397+
401398/**
402399 * When the server restarts (likely due to a crash, then the LanguageClient automatically starts it again)
403400 * we need to run some server intialization again.
0 commit comments