mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
refactor(all): language tree adaption (#1105)
This commit is contained in:
parent
0df7c4aa39
commit
6863f79118
9 changed files with 198 additions and 61 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue