refactor(ts_utils): i dont know why event it was here
This commit is contained in:
parent
f171953e43
commit
b580829379
2 changed files with 23 additions and 35 deletions
|
|
@ -27,18 +27,15 @@ end
|
||||||
---@param bufnr string|nil
|
---@param bufnr string|nil
|
||||||
---@param do_notify boolean|nil
|
---@param do_notify boolean|nil
|
||||||
---@return table|nil
|
---@return table|nil
|
||||||
function ts.get_struct_node_at_pos(row, col, bufnr, do_notify)
|
function ts.get_struct_node_at_pos(row, col, bufnr)
|
||||||
local notify = do_notify or true
|
|
||||||
local query = ts.querys.struct_block .. " " .. ts.querys.em_struct_block
|
local query = ts.querys.struct_block .. " " .. ts.querys.em_struct_block
|
||||||
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
||||||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||||
if ns == nil then
|
if ns == nil then
|
||||||
if notify then
|
u.deferred_notify("struct not found", vim.log.levels.WARN)
|
||||||
u.deferred_notify("struct not found", vim.log.levels.WARN)
|
return
|
||||||
end
|
|
||||||
else
|
|
||||||
return ns[#ns]
|
|
||||||
end
|
end
|
||||||
|
return ns[#ns]
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param row string
|
---@param row string
|
||||||
|
|
@ -46,18 +43,15 @@ end
|
||||||
---@param bufnr string|nil
|
---@param bufnr string|nil
|
||||||
---@param do_notify boolean|nil
|
---@param do_notify boolean|nil
|
||||||
---@return table|nil
|
---@return table|nil
|
||||||
function ts.get_func_method_node_at_pos(row, col, bufnr, do_notify)
|
function ts.get_func_method_node_at_pos(row, col, bufnr)
|
||||||
local notify = do_notify or true
|
|
||||||
local query = ts.querys.func .. " " .. ts.querys.method_name
|
local query = ts.querys.func .. " " .. ts.querys.method_name
|
||||||
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
||||||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||||
if ns == nil then
|
if ns == nil then
|
||||||
if notify then
|
u.deferred_notify("function not found", vim.log.levels.WARN)
|
||||||
u.deferred_notify("function not found", vim.log.levels.WARN)
|
return
|
||||||
end
|
|
||||||
else
|
|
||||||
return ns[#ns]
|
|
||||||
end
|
end
|
||||||
|
return ns[#ns]
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param row string
|
---@param row string
|
||||||
|
|
@ -65,21 +59,18 @@ end
|
||||||
---@param bufnr string|nil
|
---@param bufnr string|nil
|
||||||
---@param do_notify boolean|nil
|
---@param do_notify boolean|nil
|
||||||
---@return table|nil
|
---@return table|nil
|
||||||
function ts.get_package_node_at_pos(row, col, bufnr, do_notify)
|
function ts.get_package_node_at_pos(row, col, bufnr)
|
||||||
local notify = do_notify or true
|
if row > 10 then
|
||||||
-- stylua: ignore
|
return
|
||||||
if row > 10 then return end
|
end
|
||||||
local query = ts.querys.package
|
local query = ts.querys.package
|
||||||
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
||||||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||||
if ns == nil then
|
if ns == nil then
|
||||||
if notify then
|
u.deferred_notify("package not found", vim.log.levels.WARN)
|
||||||
u.deferred_notify("package not found", vim.log.levels.WARN)
|
return
|
||||||
return nil
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return ns[#ns]
|
|
||||||
end
|
end
|
||||||
|
return ns[#ns]
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param row string
|
---@param row string
|
||||||
|
|
@ -87,18 +78,15 @@ end
|
||||||
---@param bufnr string|nil
|
---@param bufnr string|nil
|
||||||
---@param do_notify boolean|nil
|
---@param do_notify boolean|nil
|
||||||
---@return table|nil
|
---@return table|nil
|
||||||
function ts.get_interface_node_at_pos(row, col, bufnr, do_notify)
|
function ts.get_interface_node_at_pos(row, col, bufnr)
|
||||||
local notify = do_notify or true
|
|
||||||
local query = ts.querys.interface
|
local query = ts.querys.interface
|
||||||
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
local bufn = bufnr or vim.api.nvim_get_current_buf()
|
||||||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||||
if ns == nil then
|
if ns == nil then
|
||||||
if notify then
|
u.deferred_notify("interface not found", vim.log.levels.WARN)
|
||||||
u.deferred_notify("interface not found", vim.log.levels.WARN)
|
return
|
||||||
end
|
|
||||||
else
|
|
||||||
return ns[#ns]
|
|
||||||
end
|
end
|
||||||
|
return ns[#ns]
|
||||||
end
|
end
|
||||||
|
|
||||||
return ts
|
return ts
|
||||||
|
|
|
||||||
|
|
@ -9,25 +9,25 @@ local function generate(row, col)
|
||||||
local ts_utils = require "gopher._utils.ts"
|
local ts_utils = require "gopher._utils.ts"
|
||||||
local comment, ns = nil, nil
|
local comment, ns = nil, nil
|
||||||
|
|
||||||
ns = ts_utils.get_package_node_at_pos(row, col, nil, false)
|
ns = ts_utils.get_package_node_at_pos(row, col, nil)
|
||||||
if ns ~= nil then
|
if ns ~= nil then
|
||||||
comment = "// Package " .. ns.name .. " provides " .. ns.name
|
comment = "// Package " .. ns.name .. " provides " .. ns.name
|
||||||
return comment, ns
|
return comment, ns
|
||||||
end
|
end
|
||||||
|
|
||||||
ns = ts_utils.get_struct_node_at_pos(row, col, nil, false)
|
ns = ts_utils.get_struct_node_at_pos(row, col, nil)
|
||||||
if ns ~= nil then
|
if ns ~= nil then
|
||||||
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
||||||
return comment, ns
|
return comment, ns
|
||||||
end
|
end
|
||||||
|
|
||||||
ns = ts_utils.get_func_method_node_at_pos(row, col, nil, false)
|
ns = ts_utils.get_func_method_node_at_pos(row, col, nil)
|
||||||
if ns ~= nil then
|
if ns ~= nil then
|
||||||
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
||||||
return comment, ns
|
return comment, ns
|
||||||
end
|
end
|
||||||
|
|
||||||
ns = ts_utils.get_interface_node_at_pos(row, col, nil, false)
|
ns = ts_utils.get_interface_node_at_pos(row, col, nil)
|
||||||
if ns ~= nil then
|
if ns ~= nil then
|
||||||
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
||||||
return comment, ns
|
return comment, ns
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue