Skip to content

Commit 2055bbf

Browse files
authored
feat(amazonq): option to show diff in reverse order (aws#7126)
## Problem Sometimes we need to show the diff in reverse order (left/right flipped). ## Solution Add a flag to show the diff in reverse order. Right now we will always do this in the lsp diff handler to avoid the need to create a temporary 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 3b619b0 commit 2055bbf

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { Disposable, LanguageClient, Position, TextDocumentIdentifier } from 'vs
5454
import * as jose from 'jose'
5555
import { AmazonQChatViewProvider } from './webviewProvider'
5656
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
57-
import { AmazonQPromptSettings, messages, openUrl } from 'aws-core-vscode/shared'
57+
import { amazonQDiffScheme, AmazonQPromptSettings, messages, openUrl } from 'aws-core-vscode/shared'
5858
import { DefaultAmazonQAppInitContext, messageDispatcher, EditorContentController } from 'aws-core-vscode/amazonq'
5959

6060
export function registerLanguageServerEventListener(languageClient: LanguageClient, provider: AmazonQChatViewProvider) {
@@ -420,20 +420,24 @@ export function registerMessageListeners(
420420
})
421421

422422
languageClient.onNotification(openFileDiffNotificationType.method, async (params: OpenFileDiffParams) => {
423-
const edc = new EditorContentController()
423+
const ecc = new EditorContentController()
424424
const uri = params.originalFileUri
425425
const doc = await vscode.workspace.openTextDocument(uri)
426426
const entireDocumentSelection = new vscode.Selection(
427427
new vscode.Position(0, 0),
428428
new vscode.Position(doc.lineCount - 1, doc.lineAt(doc.lineCount - 1).text.length)
429429
)
430-
await edc.viewDiff({
431-
context: {
432-
activeFileContext: { filePath: params.originalFileUri },
433-
focusAreaContext: { selectionInsideExtendedCodeBlock: entireDocumentSelection },
430+
await ecc.viewDiff(
431+
{
432+
context: {
433+
activeFileContext: { filePath: params.originalFileUri },
434+
focusAreaContext: { selectionInsideExtendedCodeBlock: entireDocumentSelection },
435+
},
436+
code: params.fileContent,
434437
},
435-
code: params.fileContent,
436-
})
438+
amazonQDiffScheme,
439+
true
440+
)
437441
})
438442
}
439443

packages/core/src/amazonq/commons/controllers/contentController.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class EditorContentController {
156156
*
157157
* @param message the message from Amazon Q chat
158158
*/
159-
public async viewDiff(message: any, scheme: string = amazonQDiffScheme) {
159+
public async viewDiff(message: any, scheme: string = amazonQDiffScheme, reverseOrder = false) {
160160
const errorNotification = 'Unable to Open Diff.'
161161
const { filePath, selection } = extractFileAndCodeSelectionFromMessage(message)
162162

@@ -170,8 +170,7 @@ export class EditorContentController {
170170
const disposable = vscode.workspace.registerTextDocumentContentProvider(scheme, contentProvider)
171171
await vscode.commands.executeCommand(
172172
'vscode.diff',
173-
originalFileUri,
174-
uri,
173+
...(reverseOrder ? [uri, originalFileUri] : [originalFileUri, uri]),
175174
`${path.basename(filePath)} ${amazonQTabSuffix}`
176175
)
177176

0 commit comments

Comments
 (0)