Fix #1182: fix TSRange:parent

This commit is contained in:
Stephan Seitz 2021-04-13 21:35:47 +02:00 committed by Stephan Seitz
parent 7691dda94e
commit fe6f2352c2

View file

@ -3,7 +3,6 @@ local TSRange = {}
TSRange.__index = TSRange
local api = vim.api
local parsers = require'nvim-treesitter.parsers'
local ts_utils = require'nvim-treesitter.ts_utils'
local function get_byte_offset(buf, row, col)
@ -56,9 +55,8 @@ function TSRange.from_table(buf, range)
TSRange)
end
function TSRange:parent(range)
local parser = parsers.get_parser(self.buf, parsers.get_buf_lang(range))
local root = ts_utils.get_root_for_position(range[1], range[2], parser)
function TSRange:parent()
local root = ts_utils.get_root_for_position(self[1], self[2])
return root
and root:named_descendant_for_range(self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2])