Skip to content

Commit 236dcbd

Browse files
authored
fix(codewhisperer): right context merge #4275
fix unexpected right context merge due to right context trim()
1 parent bfc5bc0 commit 236dcbd

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
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": "CodeWhisperer suggestions may be trimmed under certain criteria"
4+
}

src/codewhisperer/service/inlineCompletionItemProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class CWInlineCompletionItemProvider implements vscode.InlineCompletionIt
7575
const trimmedSuggestion = suggestion.trim()
7676
// limit of 5000 for right context matching
7777
const rightContext = document.getText(new vscode.Range(pos, document.positionAt(document.offsetAt(pos) + 5000)))
78-
const overlap = getPrefixSuffixOverlap(trimmedSuggestion, rightContext.trim())
78+
const overlap = getPrefixSuffixOverlap(trimmedSuggestion, rightContext)
7979
const overlapIndex = suggestion.lastIndexOf(overlap)
8080
if (overlapIndex >= 0) {
8181
const truncated = suggestion.slice(0, overlapIndex)

src/test/codewhisperer/service/inlineCompletionService.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,6 @@ describe('inlineCompletionService', function () {
141141
const result = provider.truncateOverlapWithRightContext(mockEditor.document, mockSuggestion, cursorPosition)
142142
assert.strictEqual(result, '')
143143
})
144-
145-
it('ignores the space at the start of right context', async function () {
146-
const testRightContext = '\n\n\n\nreturn target'
147-
const mockEditor = createMockTextEditor(`${doc}${testRightContext}`, fileName, language)
148-
const mockSuggestion = 'return target\n'
149-
const cursorPosition = new vscode.Position(2, 0)
150-
const result = provider.truncateOverlapWithRightContext(mockEditor.document, mockSuggestion, cursorPosition)
151-
assert.strictEqual(result, '')
152-
})
153144
})
154145
})
155146

0 commit comments

Comments
 (0)