Skip to content

Commit 6ca54fc

Browse files
authored
feat(amazonq): handle context command and open file for chat with lsp (#6999)
## Problem for agentic chat with language server, we need client to handle open files and update context command ## Solution --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent d457022 commit 6ca54fc

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ import {
3232
ShowSaveFileDialogParams,
3333
LSPErrorCodes,
3434
tabBarActionRequestType,
35+
ShowDocumentParams,
36+
ShowDocumentResult,
37+
ShowDocumentRequest,
38+
contextCommandsNotificationType,
39+
ContextCommandParams,
3540
} from '@aws/language-server-runtimes/protocol'
3641
import { v4 as uuidv4 } from 'uuid'
3742
import * as vscode from 'vscode'
@@ -286,6 +291,23 @@ export function registerMessageListeners(
286291
targetUri: targetUri.toString(),
287292
}
288293
})
294+
295+
languageClient.onRequest<ShowDocumentParams, ShowDocumentResult>(
296+
ShowDocumentRequest.method,
297+
async (params: ShowDocumentParams): Promise<ShowDocumentParams | ResponseError<ShowDocumentResult>> => {
298+
const uri = vscode.Uri.parse(params.uri)
299+
const doc = await vscode.workspace.openTextDocument(uri)
300+
await vscode.window.showTextDocument(doc, { preview: false })
301+
return params
302+
}
303+
)
304+
305+
languageClient.onNotification(contextCommandsNotificationType.method, (params: ContextCommandParams) => {
306+
void provider.webview?.postMessage({
307+
command: contextCommandsNotificationType.method,
308+
params: params,
309+
})
310+
})
289311
}
290312

291313
function isServerEvent(command: string) {

packages/amazonq/test/unit/amazonq/lsp/chat/messages.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('registerMessageListeners', () => {
2727
error: errorStub,
2828
sendNotification: sandbox.stub(),
2929
onRequest: sandbox.stub(),
30+
onNotification: sandbox.stub(),
3031
} as unknown as LanguageClient
3132

3233
provider = {

0 commit comments

Comments
 (0)