fix(edit): track fence state so apply keeps nested code blocks in markdown files#12594
Open
rodboev wants to merge 1 commit into
Open
fix(edit): track fence state so apply keeps nested code blocks in markdown files#12594rodboev wants to merge 1 commit into
rodboev wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #7143
Summary
Applying edits to markdown files truncates the file at the first fenced code block: the diff flashes and the saved file is cut short, or the model's wrapper fence leaks into the file. README and docs edits are the common casualty.
Root cause
stopAtLinesWithMarkdownSupport(core/utils/streamMarkdownUtils.ts) decides where the model's prefilled outer fence ends. For markdown files it had two paths: a tracker-based one used only when the file contains explicit```md-tagged blocks, and a simple scan that stops at the first bareline. Any markdown file whose inner blocks use other language tags (````javascript,```bash ````) hits the simple scan and is truncated at the first inner closing fence.Changes
core/utils/streamMarkdownUtils.ts: replaced both paths with a single CommonMark-based scan:```` correctly closes a four-backtick block, and an info-string line inside a block is content)core/utils/streamMarkdownUtils.vitest.ts: 10 new cases (single/sequential/nested blocks, four-backtick fences, unclosed inner fence, info-string-inside-block, short/over-indented lines, non-markdown regression)What this doesn't change
shouldStopAtMarkdownBlockandMarkdownBlockStateTrackerconsumers elsewhere (the tracker import here is now type-only)Checklist
Screen recording or screenshot
N/A — streaming parser fix; the user-visible effect is markdown files no longer truncating at the first inner code block on apply.
Tests
cd core && npx vitest run utils/streamMarkdownUtils.vitest.ts— 13/13 passing (3 existing + 10 new). Covers: fence-depth handling for plain, sequential, nested, and four-backtick blocks; unclosed inner fences; info-string lines inside open blocks; short/over-indented backtick lines; and the non-markdown stop-at-first-fence regression guard.cd core && npx vitest run utils/markdownUtils.vitest.ts— 34/34 passing (adjacent module regression guard).Summary by cubic
Tracks and closes fenced code blocks in markdown so applying edits no longer truncates files or leaks the wrapper fence. Fixes #7143.
core/utils/streamMarkdownUtils.ts(tracks backtick count, ≤3-space indent, and non-nesting).Written for commit e8f1c9d. Summary will update on new commits.