Skip to content

Commit ccbdf48

Browse files
authored
feat(lsp): add handler for openFileDiff notification (#7119)
## Problem Handler is missing for openFileDiff lsp workspace command ## Solution Add notification handler, extend the existing viewDiff implementation by passing in the final content for the temp file --- - 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 7bb66e1 commit ccbdf48

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import {
3939
ShowDocumentRequest,
4040
contextCommandsNotificationType,
4141
ContextCommandParams,
42+
openFileDiffNotificationType,
43+
OpenFileDiffParams,
4244
LINK_CLICK_NOTIFICATION_METHOD,
4345
LinkClickParams,
4446
INFO_LINK_CLICK_NOTIFICATION_METHOD,
@@ -50,7 +52,7 @@ import * as jose from 'jose'
5052
import { AmazonQChatViewProvider } from './webviewProvider'
5153
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
5254
import { AmazonQPromptSettings, messages, openUrl } from 'aws-core-vscode/shared'
53-
import { DefaultAmazonQAppInitContext, messageDispatcher } from 'aws-core-vscode/amazonq'
55+
import { DefaultAmazonQAppInitContext, messageDispatcher, EditorContentController } from 'aws-core-vscode/amazonq'
5456

5557
export function registerLanguageServerEventListener(languageClient: LanguageClient, provider: AmazonQChatViewProvider) {
5658
languageClient.info(
@@ -395,6 +397,23 @@ export function registerMessageListeners(
395397
params: params,
396398
})
397399
})
400+
401+
languageClient.onNotification(openFileDiffNotificationType.method, async (params: OpenFileDiffParams) => {
402+
const edc = new EditorContentController()
403+
const uri = params.originalFileUri
404+
const doc = await vscode.workspace.openTextDocument(uri)
405+
const entireDocumentSelection = new vscode.Selection(
406+
new vscode.Position(0, 0),
407+
new vscode.Position(doc.lineCount - 1, doc.lineAt(doc.lineCount - 1).text.length)
408+
)
409+
await edc.viewDiff({
410+
context: {
411+
activeFileContext: { filePath: params.originalFileUri },
412+
focusAreaContext: { selectionInsideExtendedCodeBlock: entireDocumentSelection },
413+
},
414+
code: params.fileContent,
415+
})
416+
})
398417
}
399418

400419
function isServerEvent(command: string) {

packages/core/src/amazonq/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export * as authConnection from '../auth/connection'
4747
export * as featureConfig from './webview/generators/featureConfig'
4848
export * as messageDispatcher from './webview/messages/messageDispatcher'
4949
import { FeatureContext } from '../shared/featureConfig'
50+
export { EditorContentController } from './commons/controllers/contentController'
5051

5152
/**
5253
* main from createMynahUI is a purely browser dependency. Due to this

0 commit comments

Comments
 (0)