treesitter: propagate on_detach event properly

This commit is contained in:
Björn Linse
2021-02-06 10:17:40 +01:00
parent 230f2ff381
commit fa5f583981
3 changed files with 19 additions and 3 deletions

View File

@@ -113,8 +113,9 @@ function TSHighlighter.new(tree, opts)
opts = opts or {}
self.tree = tree
tree:register_cbs {
on_changedtree = function(...) self:on_changedtree(...) end,
on_bytes = function(...) self:on_bytes(...) end
on_changedtree = function(...) self:on_changedtree(...) end;
on_bytes = function(...) self:on_bytes(...) end;
on_detach = function(...) self:on_detach(...) end;
}
self.bufnr = tree:source()
@@ -176,6 +177,10 @@ function TSHighlighter:on_bytes(_, _, start_row, _, _, _, _, _, new_end)
a.nvim__buf_redraw_range(self.bufnr, start_row, start_row + new_end + 1)
end
function TSHighlighter:on_detach()
self:destroy()
end
function TSHighlighter:on_changedtree(changes)
for _, ch in ipairs(changes or {}) do
a.nvim__buf_redraw_range(self.bufnr, ch[1], ch[3]+1)