Skip to content

Commit f8f154f

Browse files
authored
codewhisperer: filter out blank code chunk (#3747)
1 parent ccfc0ff commit f8f154f

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix inproper request format when sending empty supplemental context"
4+
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererFileContextProvider.kt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
114114
} else if (!isTst && targetContext.programmingLanguage.isSupplementalContextSupported()) {
115115
extractSupplementalFileContextForSrc(psiFile, targetContext)
116116
} else {
117-
LOG.debug { "${ if (isTst) "UTG" else "CrossFile" } not supported for ${targetContext.programmingLanguage.languageId}" }
117+
LOG.debug { "${if (isTst) "UTG" else "CrossFile"} not supported for ${targetContext.programmingLanguage.languageId}" }
118118
null
119119
}
120120

@@ -217,7 +217,11 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
217217
// we use nextChunk as supplemental context
218218
return top3Chunks.mapNotNull { bm25Result ->
219219
contentToChunk[bm25Result.docString]?.let {
220-
Chunk(content = it.nextChunk, path = it.path, score = bm25Result.score)
220+
if (it.nextChunk.isNotBlank()) {
221+
Chunk(content = it.nextChunk, path = it.path, score = bm25Result.score)
222+
} else {
223+
null
224+
}
221225
}
222226
}
223227
}
@@ -230,17 +234,23 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
230234

231235
return focalFile?.let { file ->
232236
val relativePath = contentRootPathProvider.getPathToElement(project, file, null) ?: file.path
233-
listOf(
234-
Chunk(
235-
content = CodeWhispererConstants.Utg.UTG_PREFIX + file.content().let {
236-
it.substring(
237-
0,
238-
minOf(it.length, CodeWhispererConstants.Utg.UTG_SEGMENT_SIZE)
239-
)
240-
},
241-
path = relativePath
237+
val content = file.content()
238+
239+
if (content.isBlank()) {
240+
emptyList()
241+
} else {
242+
listOf(
243+
Chunk(
244+
content = CodeWhispererConstants.Utg.UTG_PREFIX + file.content().let {
245+
it.substring(
246+
0,
247+
minOf(it.length, CodeWhispererConstants.Utg.UTG_SEGMENT_SIZE)
248+
)
249+
},
250+
path = relativePath
251+
)
242252
)
243-
)
253+
}
244254
}.orEmpty()
245255
}
246256

0 commit comments

Comments
 (0)