Skip to content

Commit c96646d

Browse files
committed
patch
1 parent 27dc46d commit c96646d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/core/src/codewhisperer/util/supplementalContext/supplementalContextUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function truncateSuppelementalContext(
100100
let curTotalLength = c.reduce((acc, cur) => {
101101
return acc + cur.content.length
102102
}, 0)
103-
while (curTotalLength >= 20480) {
103+
while (curTotalLength >= 20480 && c.length - 1 >= 0) {
104104
const last = c[c.length - 1]
105105
c = c.slice(0, -1)
106106
curTotalLength -= last.content.length
@@ -122,7 +122,7 @@ export function truncateLineByLine(input: string, l: number): string {
122122
const shouldAddNewLineBack = input.endsWith(os.EOL)
123123
let lines = input.trim().split(os.EOL)
124124
let curLen = input.length
125-
while (curLen > maxLength) {
125+
while (curLen > maxLength && lines.length - 1 >= 0) {
126126
const last = lines[lines.length - 1]
127127
lines = lines.slice(0, -1)
128128
curLen -= last.length + 1

0 commit comments

Comments
 (0)