fix(treesitter): allow ranges in set_included_ranges

This commit is contained in:
Thomas Vigouroux
2020-11-10 15:21:04 +01:00
parent 9ff6760b2d
commit 52d76f0a32
3 changed files with 97 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
local a = vim.api
local query = require'vim.treesitter.query'
local language = require'vim.treesitter.language'
@@ -234,6 +235,24 @@ end
--
-- @param regions A list of regions this tree should manange and parse.
function LanguageTree:set_included_regions(regions)
-- Transform the tables from 4 element long to 6 element long (with byte offset)
for _, region in ipairs(regions) do
for i, range in ipairs(region) do
if type(range) == "table" and #range == 4 then
-- TODO(vigoux): I don't think string parsers are useful for now
if type(self._source) == "number" then
local start_row, start_col, end_row, end_col = unpack(range)
-- Easy case, this is a buffer parser
-- TODO(vigoux): proper byte computation here, and account for EOL ?
local start_byte = a.nvim_buf_get_offset(self.bufnr, start_row) + start_col
local end_byte = a.nvim_buf_get_offset(self.bufnr, end_row) + end_col
region[i] = { start_row, start_col, start_byte, end_row, end_col, end_byte }
end
end
end
end
self._regions = regions
-- Trees are no longer valid now that we have changed regions.
-- TODO(vigoux,steelsojka): Look into doing this smarter so we can use some of the