Skip to content

Commit e771ea4

Browse files
committed
Revert "fix(amazonq): update Q profile and customizations on language-servers crash restart (aws#7671)"
This reverts commit 88caf6b, reversing changes made to d6fc897.
1 parent b94f0f6 commit e771ea4

File tree

6 files changed

+18
-521
lines changed

6 files changed

+18
-521
lines changed

packages/amazonq/src/lsp/client.ts

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -264,59 +264,6 @@ async function initializeAuth(client: LanguageClient): Promise<AmazonQLspAuth> {
264264
return auth
265265
}
266266

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-
320267
async function onLanguageServerReady(
321268
extensionContext: vscode.ExtensionContext,
322269
auth: AmazonQLspAuth,
@@ -348,7 +295,14 @@ async function onLanguageServerReady(
348295
// We manually push the cached values the first time since event handlers, which should push, may not have been setup yet.
349296
// Execution order is weird and should be fixed in the flare implementation.
350297
// 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+
}
352306

353307
toDispose.push(
354308
inlineManager,
@@ -450,6 +404,13 @@ async function onLanguageServerReady(
450404
// Set this inside onReady so that it only triggers on subsequent language server starts (not the first)
451405
onServerRestartHandler(client, auth)
452406
)
407+
408+
async function sendProfileToLsp(client: LanguageClient) {
409+
await pushConfigUpdate(client, {
410+
type: 'profile',
411+
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
412+
})
413+
}
453414
}
454415

455416
/**
@@ -469,21 +430,8 @@ function onServerRestartHandler(client: LanguageClient, auth: AmazonQLspAuth) {
469430
// TODO: Port this metric override to common definitions
470431
telemetry.languageServer_crash.emit({ id: 'AmazonQ' })
471432

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)
487435
})
488436
}
489437

packages/amazonq/src/lsp/config.ts

Lines changed: 1 addition & 9 deletions
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, getLogger } from 'aws-core-vscode/shared'
6+
import { DevSettings, getServiceEnvVarConfig, BaseLspInstaller } from 'aws-core-vscode/shared'
77
import { LanguageClient } from 'vscode-languageclient'
88
import {
99
DidChangeConfigurationNotification,
@@ -68,31 +68,23 @@ 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-
7371
switch (config.type) {
7472
case 'profile':
75-
logger.debug(`Pushing profile configuration: ${config.profileArn || 'undefined'}`)
7673
await client.sendRequest(updateConfigurationRequestType.method, {
7774
section: 'aws.q',
7875
settings: { profileArn: config.profileArn },
7976
})
80-
logger.debug(`Profile configuration pushed successfully`)
8177
break
8278
case 'customization':
83-
logger.debug(`Pushing customization configuration: ${config.customization || 'undefined'}`)
8479
client.sendNotification(DidChangeConfigurationNotification.type.method, {
8580
section: 'aws.q',
8681
settings: { customization: config.customization },
8782
})
88-
logger.debug(`Customization configuration pushed successfully`)
8983
break
9084
case 'logLevel':
91-
logger.debug(`Pushing log level configuration`)
9285
client.sendNotification(DidChangeConfigurationNotification.type.method, {
9386
section: 'aws.logLevel',
9487
})
95-
logger.debug(`Log level configuration pushed successfully`)
9688
break
9789
}
9890
}

0 commit comments

Comments
 (0)