Skip to content

Commit 64bf472

Browse files
authored
fix(amazonq): inline chat onReject should revert to initial document state (#8599)
## Problem ## Solution simply revert to whatever document initial content is --- - 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 608b890 commit 64bf472

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "fix: inline chat fails to revert to original state after users reject"
4+
}

packages/amazonq/src/inlineChat/controller/inlineChatController.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ export class InlineChatController {
117117
this.task
118118
)
119119
}
120-
const insertions = task.diff.filter((diff) => diff.type === 'insertion')
120+
// Revert to the original document text
121+
const fullRange = new vscode.Range(
122+
task.document.positionAt(0),
123+
task.document.positionAt(task.document.getText().length)
124+
)
121125
await editor.edit(
122126
(editBuilder) => {
123-
for (const insertion of insertions) {
124-
editBuilder.delete(insertion.range)
125-
}
127+
editBuilder.replace(fullRange, task.originalDocumentText)
126128
},
127129
{ undoStopAfter: false, undoStopBefore: false }
128130
)

packages/amazonq/src/inlineChat/controller/inlineTask.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export class InlineTask {
4747
public selectedText: string
4848
public languageName: string | undefined
4949

50+
public readonly originalDocumentText: string
51+
5052
public partialSelectedText: string | undefined
5153
public partialSelectedTextRight: string | undefined
5254

@@ -67,6 +69,7 @@ export class InlineTask {
6769
) {
6870
this.selectedRange = textDocumentUtil.expandSelectionToFullLines(document, selection)
6971
this.selectedText = document.getText(this.selectedRange)
72+
this.originalDocumentText = document.getText()
7073
this.languageName = extractLanguageNameFromFile(document)
7174
}
7275

0 commit comments

Comments
 (0)