Skip to content

Commit ce027e8

Browse files
committed
Merge branch 'nep-prefix' into nep-prefix-backup
2 parents 0fda294 + 1833db6 commit ce027e8

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import { applyPatch, createPatch } from 'diff'
1616
import { EditSuggestionState } from '../editSuggestionState'
1717
import { debounce } from 'aws-core-vscode/utils'
1818

19-
function logSuggestionFailure(type: 'DISCARD' | 'REJECT', reason: string, suggestionContent: string) {
19+
function logSuggestionFailure(type: 'REJECT', reason: string, suggestionContent: string) {
2020
getLogger('nextEditPrediction').debug(
2121
`Auto ${type} edit suggestion with reason=${reason}, suggetion: ${suggestionContent}`
2222
)
2323
}
2424

2525
const autoRejectEditCursorDistance = 25
2626
const maxPrefixRetryCharDiff = 5
27-
const docChangedHandlerDeboucneInMs = 750
27+
const rerenderDeboucneInMs = 500
2828

2929
enum RejectReason {
3030
DocumentChange = 'Invalid patch due to document change',
@@ -67,7 +67,6 @@ export class EditsSuggestionSvg {
6767
// For cursorChangeListener to access
6868
this.startLine = startLine
6969

70-
// TODO: To investigate why it fails and patch [generateDiffSvg]
7170
if (newCode.length === 0) {
7271
this.logger.warn('not able to apply provided edit suggestion, skip rendering')
7372
return
@@ -76,24 +75,7 @@ export class EditsSuggestionSvg {
7675
if (svgImage) {
7776
const documentChangedListener = (this.documentChangedListener ??=
7877
vscode.workspace.onDidChangeTextDocument(async (e) => {
79-
if (e.contentChanges.length <= 0) {
80-
return
81-
}
82-
if (e.document !== this.editor.document) {
83-
return
84-
}
85-
if (vsCodeState.isCodeWhispererEditing) {
86-
return
87-
}
88-
if (getContext('aws.amazonq.editSuggestionActive') === false) {
89-
return
90-
}
91-
92-
// TODO: handle multi-contentChanges scenario
93-
const diff = e.contentChanges[0] ? e.contentChanges[0].text : ''
94-
this.logger.info(`docChange sessionId=${this.session.sessionId}, contentChange=${diff}`)
95-
this.docChanged += e.contentChanges[0].text
96-
await this.debouncedOnDocChanged(e)
78+
await this.onDocChange(e)
9779
}))
9880

9981
const cursorChangedListener = (this.cursorChangedListener ??=
@@ -141,12 +123,24 @@ export class EditsSuggestionSvg {
141123
}
142124
}
143125

144-
debouncedOnDocChanged = debounce(
145-
async (e: vscode.TextDocumentChangeEvent) => await this.onDocChange(e),
146-
docChangedHandlerDeboucneInMs
147-
)
148-
149126
private async onDocChange(e: vscode.TextDocumentChangeEvent) {
127+
if (e.contentChanges.length <= 0) {
128+
return
129+
}
130+
if (e.document !== this.editor.document) {
131+
return
132+
}
133+
if (vsCodeState.isCodeWhispererEditing) {
134+
return
135+
}
136+
if (getContext('aws.amazonq.editSuggestionActive') === false) {
137+
return
138+
}
139+
140+
// TODO: handle multi-contentChanges scenario
141+
const diff = e.contentChanges[0] ? e.contentChanges[0].text : ''
142+
this.logger.info(`docChange sessionId=${this.session.sessionId}, contentChange=${diff}`)
143+
this.docChanged += e.contentChanges[0].text
150144
/**
151145
* 1. Take the diff returned by the model and apply it to the code we originally sent to the model
152146
* 2. Do a diff between the above code and what's currently in the editor
@@ -167,7 +161,7 @@ export class EditsSuggestionSvg {
167161
} else {
168162
// Close the previoius popup and rerender it
169163
this.logger.info(`calling rerender with suggestion\n ${updatedPatch.insertText as string}`)
170-
await this.rerender(updatedPatch)
164+
await this.debouncedRerender(updatedPatch)
171165
}
172166
} else {
173167
this.autoReject(RejectReason.NotApplicableToOriginal)
@@ -184,6 +178,12 @@ export class EditsSuggestionSvg {
184178
await decorationManager.clearDecorations(this.editor, [])
185179
}
186180

181+
debouncedRerender = debounce(
182+
async (suggestion: InlineCompletionItemWithReferences) => await this.rerender(suggestion),
183+
rerenderDeboucneInMs,
184+
true
185+
)
186+
187187
private async rerender(suggestion: InlineCompletionItemWithReferences) {
188188
await decorationManager.clearDecorations(this.editor, [])
189189
await this.show(suggestion)

0 commit comments

Comments
 (0)