diff options
author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-11-10 15:21:04 +0100 |
---|---|---|
committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-11-23 15:09:32 +0100 |
commit | 52d76f0a3273ca8d7c6a50c6cf4e44cfde939f73 (patch) | |
tree | ce98657783ef0584092e36f00ff2659afc35b5c3 /runtime/lua | |
parent | 9ff6760b2da9a227a2901adfea24d4ec634d551a (diff) | |
download | rneovim-52d76f0a3273ca8d7c6a50c6cf4e44cfde939f73.tar.gz rneovim-52d76f0a3273ca8d7c6a50c6cf4e44cfde939f73.tar.bz2 rneovim-52d76f0a3273ca8d7c6a50c6cf4e44cfde939f73.zip |
fix(treesitter): allow ranges in set_included_ranges
Diffstat (limited to 'runtime/lua')
-rw-r--r-- | runtime/lua/vim/treesitter/languagetree.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua index ed07e73a55..70e2ac4c62 100644 --- a/runtime/lua/vim/treesitter/languagetree.lua +++ b/runtime/lua/vim/treesitter/languagetree.lua @@ -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 |