Skip to content

Commit 812fec8

Browse files
committed
fix: chatOptions are missing in q chat
1 parent 85d3e7e commit 812fec8

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,42 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
115115
}
116116

117117
provider.onDidResolveWebview(() => {
118-
void provider.webview?.postMessage({
119-
command: CHAT_OPTIONS,
120-
params: chatOptions,
121-
})
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
122146
})
123147

124148
// This passes through metric data from LSP events to Toolkit telemetry with all fields from the LSP server
125149
languageClient.onTelemetry((e) => {
126150
const telemetryName: string = e.name
127151

128152
if (telemetryName in telemetry) {
129-
languageClient.info(`[Telemetry] Emitting ${telemetryName} telemetry: ${JSON.stringify(e.data)}`)
153+
languageClient.info(`[VSCode Telemetry] Emitting ${telemetryName} telemetry: ${JSON.stringify(e.data)}`)
130154
telemetry[telemetryName as keyof TelemetryBase].emit(e.data)
131155
}
132156
})

0 commit comments

Comments
 (0)