feat(_utils.ts): get package

This commit is contained in:
Smirnov Oleksandr 2022-06-29 15:43:39 +03:00
parent 1db0914cfc
commit f9693c92ad

View file

@ -4,6 +4,7 @@ local M = {
querys = {
struct_block = [[((type_declaration (type_spec name:(type_identifier) @struct.name type: (struct_type)))@struct.declaration)]],
em_struct_block = [[(field_declaration name:(field_identifier)@struct.name type: (struct_type)) @struct.declaration]],
package = [[(package_clause (package_identifier)@package.name)@package.clause]],
method_name = [[((method_declaration receiver: (parameter_list)@method.receiver name: (field_identifier)@method.name body:(block))@method.declaration)]],
func = [[((function_declaration name: (identifier)@function.name) @function.declaration)]],
},
@ -49,4 +50,22 @@ function M.get_func_method_node_at_pos(row, col, bufnr)
end
end
---@param row string
---@param col string
---@param bufnr string
---@return table|nil
function M.get_package_node_at_pos(row, col, bufnr)
-- stylua: ignore
if row > 10 then return end
local query = M.querys.package
local bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then
u.notify("package not found", "warn")
return nil
else
return ns[#ns]
end
end
return M