Skip to content

Commit 219c586

Browse files
authored
fix(codewhisperer): filter out blank code chunk (#3642)
1 parent 1dac097 commit 219c586

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
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: improper request format when sending empty supplemental context"
4+
}

src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export async function fetchSupplementalContextForSrc(
6868
})
6969
}
7070

71-
return supplementalContexts
71+
// DO NOT send code chunk with empty content
72+
return supplementalContexts.filter(item => {
73+
item.content.trim().length !== 0
74+
})
7275
}
7376

7477
function findBestKChunkMatches(chunkInput: Chunk, chunkReferences: Chunk[], k: number): Chunk[] {

src/codewhisperer/util/supplementalContext/utgUtils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ function generateSupplementalContextFromFocalFile(
7777
): CodeWhispererSupplementalContextItem[] {
7878
const fileContent = fs.readFileSync(vscode.Uri.file(filePath!).fsPath, 'utf-8')
7979

80-
// TODO (Metrics) Publish fileContent.lenth to record the length of focal files observed.
81-
// We prepend the content with 'UTG' to inform the server side.
80+
// DO NOT send code chunk with empty content
81+
if (fileContent.trim().length === 0) {
82+
return []
83+
}
8284

8385
return [
8486
{

0 commit comments

Comments
 (0)