Skip to content

Commit ba89b52

Browse files
committed
fix: using event-driven approach instead of arbitary values for fixing the icon missing issue
1 parent 9a32e97 commit ba89b52

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

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

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
LINK_CLICK_NOTIFICATION_METHOD,
4949
LinkClickParams,
5050
INFO_LINK_CLICK_NOTIFICATION_METHOD,
51+
READY_NOTIFICATION_METHOD,
5152
buttonClickRequestType,
5253
ButtonClickResult,
5354
CancellationTokenSource,
@@ -114,37 +115,6 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
114115
chatOptions.quickActions.quickActionsCommandGroups[0].groupName = 'Quick Actions'
115116
}
116117

117-
provider.onDidResolveWebview(() => {
118-
// Give the webview a moment to fully initialize before sending messages
119-
setTimeout(() => {
120-
if (provider.webview) {
121-
// Ensure webview is ready and properly initialized
122-
const sendPromise = provider.webview
123-
.postMessage({
124-
command: CHAT_OPTIONS,
125-
params: chatOptions,
126-
})
127-
.then(() => {
128-
// Log success only after message is confirmed sent
129-
const quickActionCommands =
130-
chatOptions?.quickActions?.quickActionsCommandGroups?.[0]?.commands || []
131-
const quickActionsDisplay = quickActionCommands.map((cmd: any) => cmd.command).join(', ')
132-
languageClient.info(
133-
`[VSCode Client] Chat options flags: mcpServers=${chatOptions?.mcpServers}, history=${chatOptions?.history}, export=${chatOptions?.export}, quickActions=[${quickActionsDisplay}]`
134-
)
135-
})
136-
137-
// Handle potential errors separately since PromiseLike might not have catch
138-
sendPromise.then(undefined, (err: Error) => {
139-
// Log any errors that occur during message sending
140-
languageClient.error(`[VSCode Client] Failed to send CHAT_OPTIONS: ${err.message}`)
141-
})
142-
} else {
143-
languageClient.warn(`[VSCode Client] Cannot send CHAT_OPTIONS: webview is not available`)
144-
}
145-
}, 100) // Short delay of 100ms to ensure webview is ready
146-
})
147-
148118
// This passes through metric data from LSP events to Toolkit telemetry with all fields from the LSP server
149119
languageClient.onTelemetry((e) => {
150120
const telemetryName: string = e.name
@@ -177,6 +147,10 @@ export function registerMessageListeners(
177147
encryptionKey: Buffer
178148
) {
179149
const chatStreamTokens = new Map<string, CancellationTokenSource>() // tab id -> token
150+
151+
// Keep track of pending chat options to send when webview UI is ready
152+
const pendingChatOptions = languageClient.initializeResult?.awsServerCapabilities?.chatOptions
153+
180154
provider.webview?.onDidReceiveMessage(async (message) => {
181155
languageClient.info(`[VSCode Client] Received ${JSON.stringify(message)} from chat`)
182156

@@ -190,7 +164,32 @@ export function registerMessageListeners(
190164
}
191165

192166
const webview = provider.webview
167+
193168
switch (message.command) {
169+
// Handle "aws/chat/ready" event
170+
case READY_NOTIFICATION_METHOD:
171+
languageClient.info(`[VSCode Client] "aws/chat/ready" event is received, sending chat options`)
172+
if (webview && pendingChatOptions) {
173+
try {
174+
await webview.postMessage({
175+
command: CHAT_OPTIONS,
176+
params: pendingChatOptions,
177+
})
178+
179+
// Display a more readable representation of quick actions
180+
const quickActionCommands =
181+
pendingChatOptions?.quickActions?.quickActionsCommandGroups?.[0]?.commands || []
182+
const quickActionsDisplay = quickActionCommands.map((cmd: any) => cmd.command).join(', ')
183+
languageClient.info(
184+
`[VSCode Client] Chat options flags: mcpServers=${pendingChatOptions?.mcpServers}, history=${pendingChatOptions?.history}, export=${pendingChatOptions?.export}, quickActions=[${quickActionsDisplay}]`
185+
)
186+
} catch (err) {
187+
languageClient.error(
188+
`[VSCode Client] Failed to send CHAT_OPTIONS after "aws/chat/ready" event: ${(err as Error).message}`
189+
)
190+
}
191+
}
192+
break
194193
case COPY_TO_CLIPBOARD:
195194
languageClient.info('[VSCode Client] Copy to clipboard event received')
196195
try {

0 commit comments

Comments
 (0)