fixup! fixup! refactor(_utils.ts): all public methods are just adapters
This commit is contained in:
parent
ac457d0c6d
commit
9eeaab25ed
1 changed files with 6 additions and 12 deletions
|
|
@ -18,22 +18,16 @@ local queries = {
|
||||||
]],
|
]],
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param parent_type string|[string]
|
---@param parent_type [string]
|
||||||
---@param node TSNode
|
---@param node TSNode
|
||||||
---@return TSNode?
|
---@return TSNode?
|
||||||
local function get_parrent_node(parent_type, node)
|
local function get_parrent_node(parent_type, node)
|
||||||
---@type TSNode?
|
---@type TSNode?
|
||||||
local current = node
|
local current = node
|
||||||
while current do
|
while current do
|
||||||
if type(parent_type) == "string" then
|
|
||||||
if current:type() == parent_type then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
elseif type(parent_type) == "table" then
|
|
||||||
if vim.tbl_contains(parent_type, current:type()) then
|
if vim.tbl_contains(parent_type, current:type()) then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
current = current:parent()
|
current = current:parent()
|
||||||
if current == nil then
|
if current == nil then
|
||||||
|
|
@ -67,7 +61,7 @@ end
|
||||||
---@field end_line integer
|
---@field end_line integer
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param parent_type string|[string]
|
---@param parent_type [string]
|
||||||
---@param query string
|
---@param query string
|
||||||
---@return gopher.TsResult
|
---@return gopher.TsResult
|
||||||
local function do_stuff(bufnr, parent_type, query)
|
local function do_stuff(bufnr, parent_type, query)
|
||||||
|
|
@ -107,12 +101,12 @@ end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
function ts.get_package_under_cursor(bufnr)
|
function ts.get_package_under_cursor(bufnr)
|
||||||
return do_stuff(bufnr, "package_clause", queries.package)
|
return do_stuff(bufnr, { "package_clause" }, queries.package)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
function ts.get_interface_under_cursor(bufnr)
|
function ts.get_interface_under_cursor(bufnr)
|
||||||
return do_stuff(bufnr, "type_declaration", queries.interface)
|
return do_stuff(bufnr, { "type_declaration" }, queries.interface)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ts
|
return ts
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue