diff options
| author | luukvbaal <luukvbaal@gmail.com> | 2025-05-07 03:03:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-06 18:03:54 -0700 |
| commit | 2aa794826611cd4874badd2409928fd04a64a75f (patch) | |
| tree | 64dbc7223d0f4daa1785d34d719719e5dc692bf7 /runtime/lua/vim | |
| parent | fb59188b6d828066e4d4d0e18badb47bc400d9f3 (diff) | |
| download | rneovim-2aa794826611cd4874badd2409928fd04a64a75f.tar.gz rneovim-2aa794826611cd4874badd2409928fd04a64a75f.tar.bz2 rneovim-2aa794826611cd4874badd2409928fd04a64a75f.zip | |
fix(treesitter): invalidate conceal_lines cache earlier #33875
Problem: conceal_lines cache is invalidated in `on_buf`
which is too late for code calculating text height after a
buffer change but before a redraw (like `lsp/util.lua`).
Solution: Replace `on_buf` with `on_bytes` handler that invalidates
the cache and clears the marks.
Diffstat (limited to 'runtime/lua/vim')
| -rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 7801bed65c..94dad7d4c1 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -109,6 +109,15 @@ function TSHighlighter.new(tree, opts) end tree:register_cbs({ + on_bytes = function(buf) + -- Clear conceal_lines marks whenever the buffer text changes. Marks are added + -- back as either the _conceal_line or on_win callback comes across them. + local hl = TSHighlighter.active[buf] + if hl and next(hl._conceal_checked) then + api.nvim_buf_clear_namespace(buf, ns, 0, -1) + hl._conceal_checked = {} + end + end, on_changedtree = function(...) self:on_changedtree(...) end, @@ -313,7 +322,7 @@ end ---@param on_spell boolean ---@param on_conceal boolean local function on_line_impl(self, buf, line, on_spell, on_conceal) - self._conceal_checked[line] = true + self._conceal_checked[line] = self._conceal_line and true or nil self:for_each_highlight_state(function(state) local root_node = state.tstree:root() local root_start_row, _, root_end_row, _ = root_node:range() @@ -388,7 +397,6 @@ local function on_line_impl(self, buf, line, on_spell, on_conceal) api.nvim_buf_set_extmark(buf, ns, start_row, 0, { end_line = end_row, conceal_lines = '', - invalidate = true, }) end end @@ -454,19 +462,6 @@ function TSHighlighter._on_conceal_line(_, _, buf, row) end ---@private ---- Clear conceal_lines marks whenever we redraw for a buffer change. Marks are ---- added back as either the _conceal_line or on_win callback comes across them. -function TSHighlighter._on_buf(_, buf) - local self = TSHighlighter.active[buf] - if not self or not self._conceal_line then - return - end - - api.nvim_buf_clear_namespace(buf, ns, 0, -1) - self._conceal_checked = {} -end - ----@private ---@param buf integer ---@param topline integer ---@param botline integer @@ -507,7 +502,6 @@ end api.nvim_set_decoration_provider(ns, { on_win = TSHighlighter._on_win, on_line = TSHighlighter._on_line, - on_buf = TSHighlighter._on_buf, _on_spell_nav = TSHighlighter._on_spell_nav, _on_conceal_line = TSHighlighter._on_conceal_line, }) |