Skip to content

Commit

Permalink
fix(treesitter): remove redundant on_bytes callback neovim#31041
Browse files Browse the repository at this point in the history
Problem:  Treesitter highlighter implements an on_bytes callback that
          just re-marks a buffer range for redraw. The edit that
          prompted the callback will already have done that.
Solution: Remove redundant on_bytes callback from the treesitter
          highlighter module.
  • Loading branch information
luukvbaal authored Nov 17, 2024
1 parent 9c718bc commit cdc9bae
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
3 changes: 1 addition & 2 deletions runtime/doc/treesitter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1605,8 +1605,7 @@ LanguageTree:register_cbs({cbs}, {recursive})
{cbs} (`table<TSCallbackNameOn,function>`) An
|nvim_buf_attach()|-like table argument with the
following handlers:
`on_bytes` : see |nvim_buf_attach()|, but this will be
called after the parsers callback.
`on_bytes` : see |nvim_buf_attach()|.
`on_changedtree` : a callback that will be called every
time the tree has syntactical changes. It will be
passed two arguments: a table of the ranges (as node
Expand Down
10 changes: 0 additions & 10 deletions runtime/lua/vim/treesitter/highlighter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ function TSHighlighter.new(tree, opts)
opts = opts or {} ---@type { queries: table<string,string> }
self.tree = tree
tree:register_cbs({
on_bytes = function(...)
self:on_bytes(...)
end,
on_detach = function()
self:on_detach()
end,
Expand Down Expand Up @@ -214,13 +211,6 @@ function TSHighlighter:for_each_highlight_state(fn)
end
end

---@package
---@param start_row integer
---@param new_end integer
function TSHighlighter:on_bytes(_, _, start_row, _, _, _, _, _, new_end)
api.nvim__redraw({ buf = self.bufnr, range = { start_row, start_row + new_end + 1 } })
end

---@package
function TSHighlighter:on_detach()
self:destroy()
Expand Down
2 changes: 1 addition & 1 deletion runtime/lua/vim/treesitter/languagetree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ end

--- Registers callbacks for the [LanguageTree].
---@param cbs table<TSCallbackNameOn,function> An [nvim_buf_attach()]-like table argument with the following handlers:
--- - `on_bytes` : see [nvim_buf_attach()], but this will be called _after_ the parsers callback.
--- - `on_bytes` : see [nvim_buf_attach()].
--- - `on_changedtree` : a callback that will be called every time the tree has syntactical changes.
--- It will be passed two arguments: a table of the ranges (as node ranges) that
--- changed and the changed tree.
Expand Down

0 comments on commit cdc9bae

Please sign in to comment.