fix: read equation text from the parsed buffer, not the current one - #26
Open
Chiarandini wants to merge 1 commit into
Open
fix: read equation text from the parsed buffer, not the current one#26Chiarandini wants to merge 1 commit into
Chiarandini wants to merge 1 commit into
Conversation
Buffer:parse passes 0 as the treesitter source to iter_captures and
get_node_text, so both read whichever buffer happens to be current
rather than self.bufnr.
parse_view runs from the update_interval timer armed by on_lines and
WinScrolled, so leaving the markdown buffer inside that window makes the
node's range resolve against the wrong buffer:
- a longer current buffer yields an empty string, and rendering "" fails.
Drawing the resulting error message calls marks.add with length 0,
which trips assert(col_end > col) in tracker.add.
- a shorter current buffer raises "Index out of bounds" from
nvim_buf_get_text.
Both are reachable from a file containing nothing but $x+y$.
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.
Problem
Buffer:parsepasses0as the treesitter source to bothiter_capturesandget_node_text(lua/mdmath/overlay.lua:154,156), so equation text is read from whichever buffer is current, not fromself.bufnr— the buffer being parsed.parse_viewruns from theupdate_intervaltimer armed byon_linesandWinScrolled, so leaving the markdown buffer inside that window makes the node's range resolve against the wrong buffer. Two failure modes, both reachable from a file containing nothing but$x+y$:1. Current buffer long enough to cover the node's rows —
get_node_textclips to that buffer's line lengths and returns"". An empty equation is rendered at width 0, the processor errors, andEquation:_createtakes the error branch, which callsmarks.addwith a text length of0.Mark:_initthen computescol_end == colandtracker.addasserts:2. Current buffer shorter than the node's start row —
nvim_buf_get_textraisesIndex out of boundsout ofget_node_textinstead.Reproduction
Headless, no terminal or built processor required — the node processor and
terminfo.cell_sizeare stubbed, and the error callback stands in for the render failure:Before this change the second parse calls
Equation.new(buf, 0, 2, "")and asserts. After it, the second parse produces no equation at all and the buffer's existing ones are left alone.Note
parse_viewhas the same class of bug in its row range:util.get_current_view()readsline('w0')/line('w$')from the current window rather than a window showingself.bufnr. That one only mis-scopes which rows are parsed, so it is left for a separate change.