mirror of
https://github.com/neovim/neovim.git
synced 2025-12-11 17:12:40 +00:00
tree-sitter: simplify editing using the new old_byte_size parameter
This commit is contained in:
@@ -17,27 +17,12 @@ function Parser:parse()
|
|||||||
return self.tree
|
return self.tree
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_lines(self, bufnr, _, start_row, oldstopline, stop_row)
|
local function on_lines(self, bufnr, _, start_row, old_stop_row, stop_row, old_byte_size)
|
||||||
local start_byte = a.nvim_buf_get_offset(bufnr,start_row)
|
local start_byte = a.nvim_buf_get_offset(bufnr,start_row)
|
||||||
-- a bit messy, should we expose edited but not reparsed tree?
|
|
||||||
-- are multiple edits safe in general?
|
|
||||||
local root = self._parser:tree():root()
|
|
||||||
-- TODO: add proper lookup function!
|
|
||||||
local inode = root:descendant_for_point_range(oldstopline+9000,0, oldstopline,0)
|
|
||||||
if inode == nil then
|
|
||||||
local stop_byte = a.nvim_buf_get_offset(bufnr,stop_row)
|
local stop_byte = a.nvim_buf_get_offset(bufnr,stop_row)
|
||||||
self._parser:edit(start_byte,stop_byte,stop_byte,
|
local old_stop_byte = start_byte + old_byte_size
|
||||||
start_row,0,stop_row,0,stop_row,0)
|
self._parser:edit(start_byte,old_stop_byte,stop_byte,
|
||||||
else
|
start_row,0,old_stop_row,0,stop_row,0)
|
||||||
local fakeoldstoprow, fakeoldstopcol, fakebyteoldstop = inode:start()
|
|
||||||
local fake_rows = fakeoldstoprow-oldstopline
|
|
||||||
local fakestop = stop_row+fake_rows
|
|
||||||
local fakebytestop = a.nvim_buf_get_offset(bufnr,fakestop)+fakeoldstopcol
|
|
||||||
self._parser:edit(start_byte, fakebyteoldstop, fakebytestop,
|
|
||||||
start_row, 0,
|
|
||||||
fakeoldstoprow, fakeoldstopcol,
|
|
||||||
fakestop, fakeoldstopcol)
|
|
||||||
end
|
|
||||||
self.valid = false
|
self.valid = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user