Skip to content

Commit 76acb1e

Browse files
committed
fix: update Q profile and customizations on language-servers crash restart
1 parent eb3ceee commit 76acb1e

File tree

5 files changed

+500
-21
lines changed

5 files changed

+500
-21
lines changed

packages/amazonq/package.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,26 +1325,40 @@
13251325
"fontCharacter": "\\f1de"
13261326
}
13271327
},
1328-
"aws-schemas-registry": {
1328+
"aws-sagemaker-code-editor": {
13291329
"description": "AWS Contributed Icon",
13301330
"default": {
13311331
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13321332
"fontCharacter": "\\f1df"
13331333
}
13341334
},
1335-
"aws-schemas-schema": {
1335+
"aws-sagemaker-jupyter-lab": {
13361336
"description": "AWS Contributed Icon",
13371337
"default": {
13381338
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13391339
"fontCharacter": "\\f1e0"
13401340
}
13411341
},
1342-
"aws-stepfunctions-preview": {
1342+
"aws-schemas-registry": {
13431343
"description": "AWS Contributed Icon",
13441344
"default": {
13451345
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13461346
"fontCharacter": "\\f1e1"
13471347
}
1348+
},
1349+
"aws-schemas-schema": {
1350+
"description": "AWS Contributed Icon",
1351+
"default": {
1352+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1353+
"fontCharacter": "\\f1e2"
1354+
}
1355+
},
1356+
"aws-stepfunctions-preview": {
1357+
"description": "AWS Contributed Icon",
1358+
"default": {
1359+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1360+
"fontCharacter": "\\f1e3"
1361+
}
13481362
}
13491363
},
13501364
"walkthroughs": [

packages/amazonq/src/lsp/client.ts

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,55 @@ async function initializeAuth(client: LanguageClient): Promise<AmazonQLspAuth> {
223223
return auth
224224
}
225225

226+
async function initializeLanguageServerConfiguration(client: LanguageClient, context: string = 'startup') {
227+
const logger = getLogger('amazonqLsp')
228+
229+
if (AuthUtil.instance.isConnectionValid()) {
230+
logger.info(`[${context}] Connection valid, initializing language server configuration`)
231+
232+
try {
233+
// Send profile configuration
234+
logger.info(`[${context}] Sending profile configuration to language server`)
235+
await sendProfileToLsp(client)
236+
logger.info(`[${context}] Profile configuration sent successfully`)
237+
238+
// Send customization configuration
239+
logger.info(`[${context}] Sending customization configuration to language server`)
240+
await pushConfigUpdate(client, {
241+
type: 'customization',
242+
customization: getSelectedCustomization(),
243+
})
244+
logger.info(`[${context}] Customization configuration sent successfully`)
245+
} catch (error) {
246+
logger.error(`[${context}] Failed to initialize language server configuration: ${error}`)
247+
throw error
248+
}
249+
} else {
250+
logger.warn(
251+
`[${context}] Connection invalid, skipping language server configuration - this will cause authentication failures`
252+
)
253+
const activeConnection = AuthUtil.instance.auth.activeConnection
254+
const connectionState = activeConnection
255+
? AuthUtil.instance.auth.getConnectionState(activeConnection)
256+
: 'no-connection'
257+
logger.warn(`[${context}] Connection state: ${connectionState}`)
258+
}
259+
}
260+
261+
async function sendProfileToLsp(client: LanguageClient) {
262+
const logger = getLogger('amazonqLsp')
263+
const profileArn = AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn
264+
265+
logger.debug(`Sending profile to LSP: ${profileArn || 'undefined'}`)
266+
267+
await pushConfigUpdate(client, {
268+
type: 'profile',
269+
profileArn: profileArn,
270+
})
271+
272+
logger.debug(`Profile sent to LSP successfully`)
273+
}
274+
226275
async function onLanguageServerReady(
227276
extensionContext: vscode.ExtensionContext,
228277
auth: AmazonQLspAuth,
@@ -254,14 +303,7 @@ async function onLanguageServerReady(
254303
// We manually push the cached values the first time since event handlers, which should push, may not have been setup yet.
255304
// Execution order is weird and should be fixed in the flare implementation.
256305
// TODO: Revisit if we need this if we setup the event handlers properly
257-
if (AuthUtil.instance.isConnectionValid()) {
258-
await sendProfileToLsp(client)
259-
260-
await pushConfigUpdate(client, {
261-
type: 'customization',
262-
customization: getSelectedCustomization(),
263-
})
264-
}
306+
await initializeLanguageServerConfiguration(client, 'startup')
265307

266308
toDispose.push(
267309
inlineManager,
@@ -355,13 +397,6 @@ async function onLanguageServerReady(
355397
// Set this inside onReady so that it only triggers on subsequent language server starts (not the first)
356398
onServerRestartHandler(client, auth)
357399
)
358-
359-
async function sendProfileToLsp(client: LanguageClient) {
360-
await pushConfigUpdate(client, {
361-
type: 'profile',
362-
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
363-
})
364-
}
365400
}
366401

367402
/**
@@ -381,8 +416,21 @@ function onServerRestartHandler(client: LanguageClient, auth: AmazonQLspAuth) {
381416
// TODO: Port this metric override to common definitions
382417
telemetry.languageServer_crash.emit({ id: 'AmazonQ' })
383418

384-
// Need to set the auth token in the again
385-
await auth.refreshConnection(true)
419+
const logger = getLogger('amazonqLsp')
420+
logger.info('[crash-recovery] Language server crash detected, reinitializing authentication')
421+
422+
try {
423+
// Send bearer token
424+
logger.info('[crash-recovery] Refreshing connection and sending bearer token')
425+
await auth.refreshConnection(true)
426+
logger.info('[crash-recovery] Bearer token sent successfully')
427+
428+
// Send profile and customization configuration
429+
await initializeLanguageServerConfiguration(client, 'crash-recovery')
430+
logger.info('[crash-recovery] Language server configuration reinitialized successfully')
431+
} catch (error) {
432+
logger.error(`[crash-recovery] Failed to reinitialize after crash: ${error}`)
433+
}
386434
})
387435
}
388436

packages/amazonq/src/lsp/config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import * as vscode from 'vscode'
6-
import { DevSettings, getServiceEnvVarConfig, BaseLspInstaller } from 'aws-core-vscode/shared'
6+
import { DevSettings, getServiceEnvVarConfig, BaseLspInstaller, getLogger } from 'aws-core-vscode/shared'
77
import { LanguageClient } from 'vscode-languageclient'
88
import {
99
DidChangeConfigurationNotification,
@@ -68,23 +68,31 @@ export function toAmazonQLSPLogLevel(logLevel: vscode.LogLevel): LspLogLevel {
6868
* push the given config.
6969
*/
7070
export async function pushConfigUpdate(client: LanguageClient, config: QConfigs) {
71+
const logger = getLogger('amazonqLsp')
72+
7173
switch (config.type) {
7274
case 'profile':
75+
logger.debug(`Pushing profile configuration: ${config.profileArn || 'undefined'}`)
7376
await client.sendRequest(updateConfigurationRequestType.method, {
7477
section: 'aws.q',
7578
settings: { profileArn: config.profileArn },
7679
})
80+
logger.debug(`Profile configuration pushed successfully`)
7781
break
7882
case 'customization':
83+
logger.debug(`Pushing customization configuration: ${config.customization || 'undefined'}`)
7984
client.sendNotification(DidChangeConfigurationNotification.type.method, {
8085
section: 'aws.q',
8186
settings: { customization: config.customization },
8287
})
88+
logger.debug(`Customization configuration pushed successfully`)
8389
break
8490
case 'logLevel':
91+
logger.debug(`Pushing log level configuration`)
8592
client.sendNotification(DidChangeConfigurationNotification.type.method, {
8693
section: 'aws.logLevel',
8794
})
95+
logger.debug(`Log level configuration pushed successfully`)
8896
break
8997
}
9098
}

0 commit comments

Comments
 (0)