mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
buffer updates: add on_reload callback and handle it in treesitter parser
This commit is contained in:
@@ -51,7 +51,11 @@ function M._create_parser(bufnr, lang, opts)
|
||||
self:_on_detach(...)
|
||||
end
|
||||
|
||||
a.nvim_buf_attach(self:source(), false, {on_bytes=bytes_cb, on_detach=detach_cb, preview=true})
|
||||
local function reload_cb(_, ...)
|
||||
self:_on_reload(...)
|
||||
end
|
||||
|
||||
a.nvim_buf_attach(self:source(), false, {on_bytes=bytes_cb, on_detach=detach_cb, on_reload=reload_cb, preview=true})
|
||||
|
||||
self:parse()
|
||||
|
||||
|
||||
@@ -46,11 +46,16 @@ function LanguageTree.new(source, lang, opts)
|
||||
end
|
||||
|
||||
-- Invalidates this parser and all its children
|
||||
function LanguageTree:invalidate()
|
||||
function LanguageTree:invalidate(reload)
|
||||
self._valid = false
|
||||
|
||||
-- buffer was reloaded, reparse all trees
|
||||
if reload then
|
||||
self._trees = {}
|
||||
end
|
||||
|
||||
for _, child in ipairs(self._children) do
|
||||
child:invalidate()
|
||||
child:invalidate(reload)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -398,8 +403,13 @@ function LanguageTree:_on_bytes(bufnr, changed_tick,
|
||||
new_row, new_col, new_byte)
|
||||
end
|
||||
|
||||
function LanguageTree:_on_reload()
|
||||
self:invalidate(true)
|
||||
end
|
||||
|
||||
|
||||
function LanguageTree:_on_detach(...)
|
||||
self:invalidate()
|
||||
self:invalidate(true)
|
||||
self:_do_callback('detach', ...)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user