Skip to content

Commit 0abbe41

Browse files
committed
wip
1 parent f1d59c2 commit 0abbe41

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

packages/amazonq/src/app/inline/EditRendering/imageRenderer.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export class EditsSuggestionSvg {
2626
// TODO:
2727
// private readonly cursorChangedListener: vscode.Disposable
2828

29-
private readonly updatedItem: InlineCompletionItemWithReferences[] = []
29+
private readonly updatedSuggestions: InlineCompletionItemWithReferences[] = []
3030

3131
constructor(
32-
private item: InlineCompletionItemWithReferences,
32+
private suggestion: InlineCompletionItemWithReferences,
3333
private readonly editor: vscode.TextEditor,
3434
private readonly languageClient: LanguageClient,
3535
private readonly session: CodeWhispererSession,
@@ -45,14 +45,17 @@ export class EditsSuggestionSvg {
4545
return
4646
}
4747

48-
const item = this.updatedItem.length > 0 ? this.updatedItem[this.updatedItem.length - 1] : this.item
48+
const item =
49+
this.updatedSuggestions.length > 0
50+
? this.updatedSuggestions[this.updatedSuggestions.length - 1]
51+
: this.suggestion
4952

5053
try {
5154
const svgGenerationService = new SvgGenerationService()
5255
// Generate your SVG image with the file contents
5356
const currentFile = this.editor.document.uri.fsPath
5457
const { svgImage, startLine, newCode, originalCodeHighlightRange } =
55-
await svgGenerationService.generateDiffSvg(currentFile, this.item.insertText as string)
58+
await svgGenerationService.generateDiffSvg(currentFile, this.suggestion.insertText as string)
5659

5760
// TODO: To investigate why it fails and patch [generateDiffSvg]
5861
if (newCode.length === 0) {
@@ -103,7 +106,7 @@ export class EditsSuggestionSvg {
103106
*/
104107

105108
const originalCode = this.session.fileContent
106-
const appliedToOriginal = applyPatch(originalCode, this.item.insertText as string)
109+
const appliedToOriginal = applyPatch(originalCode, this.suggestion.insertText as string)
107110
try {
108111
if (appliedToOriginal) {
109112
const updatedPatch = createPatch(
@@ -112,7 +115,11 @@ export class EditsSuggestionSvg {
112115
appliedToOriginal
113116
)
114117
// show updatedPatch
115-
this.setItem(updatedPatch)
118+
this.updateSuggestion(updatedPatch)
119+
120+
if (this.updatedSuggestions.length > 5) {
121+
this.autoReject()
122+
}
116123

117124
// TODO: await
118125
this.show()
@@ -121,18 +128,21 @@ export class EditsSuggestionSvg {
121128
})
122129
.catch((e) => {})
123130
} else {
124-
// TODO:
125-
logSuggestionFailure('REJECT', 'Invalid patch due to document change', this.item.insertText as string)
126-
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
131+
this.autoReject()
127132
}
128133
} catch (e) {
129134
this.logger.info('123')
130135
}
131136
}
132137

133-
private setItem(content: string) {
138+
private autoReject() {
139+
logSuggestionFailure('REJECT', 'Invalid patch due to document change', this.suggestion.insertText as string)
140+
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
141+
}
142+
143+
private updateSuggestion(content: string) {
134144
this.logger.info(`update edit suggestion\n ${content}`)
135-
const updated: InlineCompletionItemWithReferences = { ...this.item, insertText: content }
136-
this.updatedItem.push(updated)
145+
const updated: InlineCompletionItemWithReferences = { ...this.suggestion, insertText: content }
146+
this.updatedSuggestions.push(updated)
137147
}
138148
}

0 commit comments

Comments
 (0)