Skip to content

fix(injected): clamp injected regions that run to the end of the file - #899

Open
stefanvanburen wants to merge 1 commit into
stevearc:masterfrom
stefanvanburen:fix/injected-region-at-eof
Open

fix(injected): clamp injected regions that run to the end of the file#899
stefanvanburen wants to merge 1 commit into
stevearc:masterfrom
stefanvanburen:fix/injected-region-at-eof

Conversation

@stefanvanburen

Copy link
Copy Markdown
Contributor

Treesitter reports a region that extends to EOF as ending at (line count, col 0), which is one row past the last line. That end row is used directly as a buffer index, so merge_ranges_with_prefix hits nvim_buf_get_lines' strict indexing and the whole format call fails with "Index out of bounds", leaving the buffer unformatted.

Fenced languages hide this: a closing ``` ends the region before EOF. Delimiter-less blocks do not, so a YAML block scalar as the last thing in the file reproduces it every time, as does an unclosed markdown fence.

Clamp the end of such a region to the end of the final line.

Fixes #452.

Treesitter reports a region that extends to EOF as ending at
(line count, col 0), which is one row past the last line. That end row
is used directly as a buffer index, so merge_ranges_with_prefix hits
nvim_buf_get_lines' strict indexing and the whole format call fails with
"Index out of bounds", leaving the buffer unformatted.

Fenced languages hide this: a closing ``` ends the region before EOF.
Delimiter-less blocks do not, so a YAML block scalar as the last thing
in the file reproduces it every time, as does an unclosed markdown fence.

Clamp the end of such a region to the end of the final line.

Fixes stevearc#452
@github-actions
github-actions Bot requested a review from stevearc August 31, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Injected formatter skips formatting if injected region at end of file

1 participant