Skip to content

Commit 77d4489

Browse files
committed
fix: convert highlighted text to proper type
1 parent 168806e commit 77d4489

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
7272
})
7373
}
7474

75+
function getCursorState(selection: readonly vscode.Selection[]) {
76+
return selection.map((s) => ({
77+
range: {
78+
start: {
79+
line: s.start.line,
80+
character: s.start.character,
81+
},
82+
end: {
83+
line: s.end.line,
84+
character: s.end.character,
85+
},
86+
},
87+
}))
88+
}
89+
7590
export function registerMessageListeners(
7691
languageClient: LanguageClient,
7792
provider: AmazonQChatViewProvider,
@@ -147,20 +162,21 @@ export function registerMessageListeners(
147162
break
148163
}
149164
case chatRequestType.method: {
165+
const chatParams = { ...message.params } as ChatParams
150166
const partialResultToken = uuidv4()
151167
const chatDisposable = languageClient.onProgress(chatRequestType, partialResultToken, (partialResult) =>
152-
handlePartialResult<ChatResult>(partialResult, encryptionKey, provider, message.params.tabId)
168+
handlePartialResult<ChatResult>(partialResult, encryptionKey, provider, chatParams.tabId)
153169
)
154170

155171
const editor =
156172
vscode.window.activeTextEditor ||
157173
vscode.window.visibleTextEditors.find((editor) => editor.document.languageId !== 'Log')
158174
if (editor) {
159-
message.params.cursorPosition = [editor.selection.active]
160-
message.params.textDocument = { uri: editor.document.uri.toString() }
175+
chatParams.cursorState = getCursorState(editor.selections)
176+
chatParams.textDocument = { uri: editor.document.uri.toString() }
161177
}
162178

163-
const chatRequest = await encryptRequest<ChatParams>(message.params, encryptionKey)
179+
const chatRequest = await encryptRequest<ChatParams>(chatParams, encryptionKey)
164180
const chatResult = (await languageClient.sendRequest(chatRequestType.method, {
165181
...chatRequest,
166182
partialResultToken,
@@ -169,7 +185,7 @@ export function registerMessageListeners(
169185
chatResult,
170186
encryptionKey,
171187
provider,
172-
message.params.tabId,
188+
chatParams.tabId,
173189
chatDisposable
174190
)
175191
break

0 commit comments

Comments
 (0)