Skip to content

Commit ee2c7f1

Browse files
authored
fix(codewhisperer): Fix reject userDecision event reported as Discard (#3065)
1 parent eb09af3 commit ee2c7f1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/codewhisperer/service/inlineCompletionService.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ class CodeWhispererInlineCompletionItemProvider implements vscode.InlineCompleti
104104
r: Recommendation,
105105
start: vscode.Position,
106106
end: vscode.Position,
107-
index: number
107+
index: number,
108+
prefix: string
108109
): vscode.InlineCompletionItem | undefined {
109-
const prefix = document.getText(new vscode.Range(start, end)).replace(/\r\n/g, '\n')
110+
if (!r.content.startsWith(prefix)) {
111+
return undefined
112+
}
110113
const truncatedSuggestion = this.truncateSuggestionOverlapWithRightContext(document, r.content)
111-
if (!r.content.startsWith(prefix) || truncatedSuggestion.length === 0) {
112-
//mark suggestion as Discard when it does not fit into the context
113-
RecommendationHandler.instance.setSuggestionState(index, 'Discard')
114+
if (truncatedSuggestion.length === 0) {
115+
if (RecommendationHandler.instance.getSuggestionState(index) !== 'Showed') {
116+
RecommendationHandler.instance.setSuggestionState(index, 'Discard')
117+
}
114118
return undefined
115119
}
116120
return {
@@ -158,7 +162,7 @@ class CodeWhispererInlineCompletionItemProvider implements vscode.InlineCompleti
158162
).length
159163
for (const i of iteratingIndexes) {
160164
const r = RecommendationHandler.instance.recommendations[i]
161-
const item = this.getInlineCompletionItem(document, r, start, end, i)
165+
const item = this.getInlineCompletionItem(document, r, start, end, i, prefix)
162166
if (item === undefined) {
163167
continue
164168
}

0 commit comments

Comments
 (0)