Skip to content

Commit acd6478

Browse files
fix: Developer Profile not pushed to LSP on start
Because the `AuthUtil.restore()` was called before we registered the onDidChangeRegionProvider, the expected pushConfigUpdate was not called when the server started. This resulted in the cached Developer Profile not being pushed to the LSP. This fixes that. Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 281a9c2 commit acd6478

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

packages/amazonq/src/lsp/chat/activation.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
7373

7474
disposables.push(
7575
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
76-
void pushConfigUpdate(languageClient, {
77-
type: 'profile',
78-
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
79-
})
8076
await provider.refreshWebview()
8177
}),
8278
Commands.register('aws.amazonq.updateCustomizations', () => {

packages/amazonq/src/lsp/client.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { processUtils } from 'aws-core-vscode/shared'
5454
import { activate as activateChat } from './chat/activation'
5555
import { AmazonQResourcePaths } from './lspInstaller'
5656
import { auth2 } from 'aws-core-vscode/auth'
57-
import { ConfigSection, isValidConfigSection, toAmazonQLSPLogLevel } from './config'
57+
import { ConfigSection, isValidConfigSection, pushConfigUpdate, toAmazonQLSPLogLevel } from './config'
5858
import { telemetry } from 'aws-core-vscode/telemetry'
5959

6060
const localize = nls.loadMessageBundle()
@@ -179,15 +179,31 @@ export async function startLanguageServer(
179179

180180
await client.onReady()
181181

182-
// IMPORTANT: This sets up Auth and must be called before anything attempts to use it
183-
AuthUtil.create(new auth2.LanguageClientAuth(client, clientId, encryptionKey))
184-
// Ideally this would be part of AuthUtil.create() as it restores the existing Auth connection, but we have some
185-
// future work which will need to delay this call
186-
await AuthUtil.instance.restore()
182+
/**
183+
* We use the Flare Auth language server, and our Auth client depends on it.
184+
* Because of this we initialize our Auth client **immediately** after the language server is ready.
185+
* Doing this removes the chance of something else attempting to use the Auth client before it is ready.
186+
*/
187+
await initializeAuth(client)
187188

188189
await postStartLanguageServer(client, resourcePaths, toDispose)
189190

190191
return client
192+
193+
async function initializeAuth(client: LanguageClient) {
194+
AuthUtil.create(new auth2.LanguageClientAuth(client, clientId, encryptionKey))
195+
196+
/** All must be setup before {@link AuthUtil.restore} otherwise they may not trigger when expected */
197+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
198+
void pushConfigUpdate(client, {
199+
type: 'profile',
200+
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
201+
})
202+
})
203+
204+
// Try and restore a cached connection if exists
205+
await AuthUtil.instance.restore()
206+
}
191207
}
192208

193209
async function postStartLanguageServer(

0 commit comments

Comments
 (0)