refactor(all): language tree adaption (#1105)

This commit is contained in:
Steven Sojka 2021-03-30 08:18:24 -05:00 committed by GitHub
parent 0df7c4aa39
commit 6863f79118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 198 additions and 61 deletions

View file

@ -4,6 +4,7 @@ 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)
return api.nvim_buf_get_offset(buf, row)
@ -57,8 +58,11 @@ end
function TSRange:parent(range)
local parser = parsers.get_parser(self.buf, parsers.get_buf_lang(range))
local root = parser:parse()[1]:root()
return root:named_descendant_for_range(self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2])
local root = ts_utils.get_root_for_position(range[1], range[2], parser)
return root
and root:named_descendant_for_range(self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2])
or nil
end
function TSRange:field()