Skip to content

Commit 05abaf0

Browse files
fix customizations change not being synced to lsp
Problem: A message was already set up in a previous commit to send the lsp a message when the Q customization model was changed, but it didn't work as expected. Solution: There are different lsp messages sent to indicate a change in user settings. For auth Q profile it is one type of Request, and for the customization selection, it uses a different lsp notification. Each type of message has its own handler in the language server, so if we send the message using the wrong message type, it will not be handled correctly since the correct handler is somewhere else. The notable handling functions were: - getAmazonQRelatedWorkspaceConfigs(), where it is part of the handler for `didChangeConfiguration()` - setupConfigurationListeners(), where it is part of the handler for `onUpdateConfiguration()` Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 0dc9542 commit 05abaf0

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ import { Commands, getLogger, globals, undefinedIfEmpty } from 'aws-core-vscode/
1212
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
1313
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
1414
import { AuthUtil, getSelectedCustomization } from 'aws-core-vscode/codewhisperer'
15-
import { updateConfigurationRequestType } from '@aws/language-server-runtimes/protocol'
15+
import {
16+
DidChangeConfigurationNotification,
17+
updateConfigurationRequestType,
18+
} from '@aws/language-server-runtimes/protocol'
1619

1720
export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
1821
const disposables = globals.context.subscriptions
1922

2023
// Make sure we've sent an auth profile to the language server before even initializing the UI
21-
await updateConfiguration(languageClient, {
24+
await pushConfigUpdate(languageClient, {
25+
type: 'profile',
2226
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
2327
})
2428

@@ -62,28 +66,48 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
6266

6367
disposables.push(
6468
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
65-
void updateConfiguration(languageClient, {
69+
void pushConfigUpdate(languageClient, {
70+
type: 'profile',
6671
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
6772
})
6873
await provider.refreshWebview()
6974
}),
7075
Commands.register('aws.amazonq.updateCustomizations', () => {
71-
void updateConfiguration(languageClient, {
76+
void pushConfigUpdate(languageClient, {
77+
type: 'customization',
7278
customization: undefinedIfEmpty(getSelectedCustomization().arn),
7379
})
7480
})
7581
)
7682
}
7783

78-
async function updateConfiguration(
79-
client: LanguageClient,
80-
settings: {
81-
[key: string]: string | undefined
84+
/**
85+
* Push a config value to the language server, effectively updating it with the
86+
* latest configuration from the client.
87+
*
88+
* The issue is we need to push certain configs to different places, since there are
89+
* different handlers for specific configs. So this determines the correct place to
90+
* push the given config.
91+
*/
92+
async function pushConfigUpdate(client: LanguageClient, config: QConfigs) {
93+
if (config.type === 'profile') {
94+
await client.sendRequest(updateConfigurationRequestType.method, {
95+
section: 'aws.q',
96+
settings: { profileArn: config.profileArn },
97+
})
98+
} else if (config.type === 'customization') {
99+
client.sendNotification(DidChangeConfigurationNotification.type.method, {
100+
section: 'aws.q',
101+
settings: { customization: config.customization },
102+
})
82103
}
83-
) {
84-
// update the profile on the language server
85-
await client.sendRequest(updateConfigurationRequestType.method, {
86-
section: 'aws.q',
87-
settings,
88-
})
89104
}
105+
type ProfileConfig = {
106+
type: 'profile'
107+
profileArn: string | undefined
108+
}
109+
type CustomizationConfig = {
110+
type: 'customization'
111+
customization: string | undefined
112+
}
113+
type QConfigs = ProfileConfig | CustomizationConfig

0 commit comments

Comments
 (0)