mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-15 01:40:02 -04:00
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
This commit is contained in:
parent
e96dae2404
commit
82afae9c9c
1 changed files with 4 additions and 2 deletions
|
|
@ -4,9 +4,10 @@ TSRange.__index = TSRange
|
||||||
|
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local ts_utils = require "nvim-treesitter.ts_utils"
|
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
|
||||||
local function get_byte_offset(buf, row, col)
|
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
|
end
|
||||||
|
|
||||||
function TSRange.new(buf, start_row, start_col, end_row, end_col)
|
function TSRange.new(buf, start_row, start_col, end_row, end_col)
|
||||||
|
|
@ -49,7 +50,8 @@ function TSRange.from_table(buf, range)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TSRange:parent()
|
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
|
return root
|
||||||
and root:named_descendant_for_range(self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2])
|
and root:named_descendant_for_range(self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue