mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-14 09:20:04 -04:00
Fix #1182: fix TSRange:parent
This commit is contained in:
parent
7691dda94e
commit
fe6f2352c2
1 changed files with 2 additions and 4 deletions
|
|
@ -3,7 +3,6 @@ local TSRange = {}
|
||||||
TSRange.__index = TSRange
|
TSRange.__index = TSRange
|
||||||
|
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local parsers = require'nvim-treesitter.parsers'
|
|
||||||
local ts_utils = require'nvim-treesitter.ts_utils'
|
local ts_utils = require'nvim-treesitter.ts_utils'
|
||||||
|
|
||||||
local function get_byte_offset(buf, row, col)
|
local function get_byte_offset(buf, row, col)
|
||||||
|
|
@ -56,9 +55,8 @@ function TSRange.from_table(buf, range)
|
||||||
TSRange)
|
TSRange)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TSRange:parent(range)
|
function TSRange:parent()
|
||||||
local parser = parsers.get_parser(self.buf, parsers.get_buf_lang(range))
|
local root = ts_utils.get_root_for_position(self[1], self[2])
|
||||||
local root = ts_utils.get_root_for_position(range[1], range[2], parser)
|
|
||||||
|
|
||||||
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