Skip to content

Commit d5dc175

Browse files
author
Bertan Ari
committed
fix(vscode-lm): find a pending invoke opener that spans the drain newline
1 parent e5d4657 commit d5dc175

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/api/providers/__tests__/vscode-lm.spec.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,18 @@ describe("VsCodeLmHandler", () => {
603603
).toEqual([])
604604
})
605605

606-
it("keeps an incomplete invoke buffered when the cap passes a newline inside it", async () => {
606+
it.each([
607+
{ where: "its parameter body", separator: " " },
608+
{ where: "its opening tag", separator: "\n" },
609+
])("keeps an incomplete invoke buffered when the cap passes a newline in $where", async ({ separator }) => {
607610
// The drain boundary was the first newline after the last closed block, even inside a
608611
// later open block. The filler trips the cap before that block's closing tag arrives.
609612
const padding = "p".repeat(20 * 1024)
610613
const filler = "x".repeat(240 * 1024)
611614
const openBody = `sub\n${filler}`
612615
const chunks = await collect([
613616
`<function${"_calls"}><in${"voke"} name="calculator"><parameter name="operation">${padding}</parameter></in${"voke"}> ` +
614-
`<in${"voke"} name="calculator"><parameter name="operation">sub\n`,
617+
`<in${"voke"}${separator}name="calculator"><parameter name="operation">sub\n`,
615618
filler,
616619
`</parameter></in${"voke"}></function${"_calls"}>`,
617620
])

‎src/api/providers/vscode-lm.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ function decidedSalvageEnd(text: string): number {
143143
return 0
144144
}
145145
// A newline inside a later, still-open block must not drain that block's opener as text.
146-
const nextOpen = text.slice(blockEnd, lineEnd).search(/<(?:antml:)?invoke\s+name="/i)
146+
// Search past the newline: the opener itself may span it, as in `<invoke\nname="`.
147+
const nextOpen = text.slice(blockEnd).search(/<(?:antml:)?invoke\s+name="/i)
147148
return nextOpen === -1 ? lineEnd + 1 : blockEnd + nextOpen
148149
}
149150

0 commit comments

Comments
 (0)