Add XML escaping and whitespace normalization to VS Code LM API parsing #4180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #4114
Description
This PR implements the fix proposed in the linked issue by enhancing the VS Code LM API provider’s parsing logic. Previously, tool calls emitted as raw JSON (instead of
<toolCall>
-wrapped XML) would be treated as plain chat text and echoed. This change introduces:escapeXml(value: string)
: Escapes&
,<
, and>
so that parameter values can be safely embedded in XML tags.normalizeVsCodeActionTags(xml: string)
:VsCodeLmHandler
:buildToolTag(...)
normalizeVsCodeActionTags(...)
before yielding__tests__/vscode-lm.test.ts
to verify:Reviewers should focus on:
escapeXml
andnormalizeVsCodeActionTags
for edge cases (e.g., nested or malformed tags).VsCodeLmHandler
.Test Procedure
npm test
(orpnpm test
) and verify that all new tests in__tests__/vscode-lm.test.ts
pass.{"tool": "edit", "args": {...}}
to the parser) and verify it no longer triggers a false “plain text” echo.Type of Change
src
or test files.Pre-Submission Checklist
npm run lint
).console.log
) has been removed.npm test
).main
branch.npm run changeset
if this PR includes user-facing changes or dependency updates.Screenshots / Videos
No UI changes, no screenshots necessary.
Documentation Updates
Additional Notes
This patch ensures that any minor whitespace variations or escaped XML characters no longer break the VS Code LM API tool-call parsing. If future providers output slightly different XML wrappers, the normalization layer should absorb those deviations without further changes.
Get in Touch
Discord:
vyndorialan
GitHub: ThomsenDrake
Important
Add XML escaping and whitespace normalization to VS Code LM API parsing, ensuring correct handling of tool calls with malformed or whitespace-heavy input.
escapeXml()
to escape&
,<
,>
invscode-lm.ts
.normalizeVsCodeActionTags()
to trim and collapse whitespace invscode-lm.ts
.VsCodeLmHandler
.vscode-lm.test.ts
for XML escaping and JSON to XML conversion.parseAssistantMessage.test.ts
to handle whitespace and malformed tags.TaskHeader.tsx
to inlinecondenseButton
.This description was created by
for e7d60ce. You can customize this summary. It will automatically update as commits are pushed.