aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2021-11-01 14:17:24 +0100
committerStephan Seitz <stephan.seitz@fau.de>2021-11-01 14:51:53 +0100
commit82afae9c9cdc112e3100933d4fccaf28f1af549a (patch)
treee4408b8fafb4923a03b14f543db444ca22606143 /lua
parentUpdate lockfile.json (diff)
downloadnvim-treesitter-82afae9c9cdc112e3100933d4fccaf28f1af549a.tar
nvim-treesitter-82afae9c9cdc112e3100933d4fccaf28f1af549a.tar.gz
nvim-treesitter-82afae9c9cdc112e3100933d4fccaf28f1af549a.tar.bz2
nvim-treesitter-82afae9c9cdc112e3100933d4fccaf28f1af549a.tar.lz
nvim-treesitter-82afae9c9cdc112e3100933d4fccaf28f1af549a.tar.xz
nvim-treesitter-82afae9c9cdc112e3100933d4fccaf28f1af549a.tar.zst
nvim-treesitter-82afae9c9cdc112e3100933d4fccaf28f1af549a.zip
Fix bugs in TSRange
- TSRange:new() was missing to extract the line from nvim_buf_get_lines - TSRange:parent() was only working when current buf == self.buf
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/tsrange.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/lua/nvim-treesitter/tsrange.lua b/lua/nvim-treesitter/tsrange.lua
index c816d6b25..d41585c60 100644
--- a/lua/nvim-treesitter/tsrange.lua
+++ b/lua/nvim-treesitter/tsrange.lua
@@ -4,9 +4,10 @@ TSRange.__index = TSRange
local api = vim.api
local ts_utils = require "nvim-treesitter.ts_utils"
+local parsers = require "nvim-treesitter.parsers"
local function get_byte_offset(buf, row, col)
- return api.nvim_buf_get_offset(buf, row) + vim.fn.byteidx(api.nvim_buf_get_lines(buf, row, row + 1, false), col)
+ return api.nvim_buf_get_offset(buf, row) + vim.fn.byteidx(api.nvim_buf_get_lines(buf, row, row + 1, false)[1], col)
end
function TSRange.new(buf, start_row, start_col, end_row, end_col)
@@ -49,7 +50,8 @@ function TSRange.from_table(buf, range)
end
function TSRange:parent()
- local root = ts_utils.get_root_for_position(self[1], self[2])
+ local root_lang_tree = parsers.get_parser(self.buf)
+ local root = ts_utils.get_root_for_position(self[1], self[2], root_lang_tree)
return root
and root:named_descendant_for_range(self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2])