fix: comment

This commit is contained in:
Smirnov Oleksandr 2022-10-07 17:26:26 +03:00
parent 701ed48d8f
commit bdb008ae62
2 changed files with 30 additions and 13 deletions

View file

@ -24,13 +24,17 @@ end
---@param row string ---@param row string
---@param col string ---@param col string
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_struct_node_at_pos(row, col, bufnr) function M.get_struct_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true
local query = M.querys.struct_block .. " " .. M.querys.em_struct_block local query = M.querys.struct_block .. " " .. M.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.notify("struct not found", "warn") u.notify("struct not found", "warn")
end
else else
return ns[#ns] return ns[#ns]
end end
@ -39,13 +43,17 @@ end
---@param row string ---@param row string
---@param col string ---@param col string
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_func_method_node_at_pos(row, col, bufnr) function M.get_func_method_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true
local query = M.querys.func .. " " .. M.querys.method_name local query = M.querys.func .. " " .. M.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.notify("function not found", "warn") u.notify("function not found", "warn")
end
else else
return ns[#ns] return ns[#ns]
end end
@ -54,16 +62,20 @@ end
---@param row string ---@param row string
---@param col string ---@param col string
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_package_node_at_pos(row, col, bufnr) function M.get_package_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true
-- stylua: ignore -- stylua: ignore
if row > 10 then return end if row > 10 then return end
local query = M.querys.package local query = M.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.notify("package not found", "warn") u.notify("package not found", "warn")
return nil return nil
end
else else
return ns[#ns] return ns[#ns]
end end
@ -72,13 +84,17 @@ end
---@param row string ---@param row string
---@param col string ---@param col string
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_interface_node_at_pos(row, col, bufnr) function M.get_interface_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true
local query = M.querys.interface local query = M.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.notify("interface not found", "warn") u.notify("interface not found", "warn")
end
else else
return ns[#ns] return ns[#ns]
end end

View file

@ -3,25 +3,25 @@ local ts_utils = require "gopher._utils.ts"
local function generate(row, col) local function generate(row, col)
local comment, ns = nil, nil local comment, ns = nil, nil
ns = ts_utils.get_package_node_at_pos(row, col) ns = ts_utils.get_package_node_at_pos(row, col, nil, false)
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) ns = ts_utils.get_struct_node_at_pos(row, col, nil, false)
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) ns = ts_utils.get_func_method_node_at_pos(row, col, nil, false)
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) ns = ts_utils.get_interface_node_at_pos(row, col, nil, false)
if ns ~= nil then if ns ~= nil then
comment = "// " .. ns.name .. " " .. ns.type .. " " comment = "// " .. ns.name .. " " .. ns.type .. " "
return comment, ns return comment, ns
@ -39,6 +39,7 @@ return function()
ns.dim.s.c, ns.dim.s.c,
}) })
---@diagnostic disable-next-line: param-type-mismatch
vim.fn.append(row - 1, comment) vim.fn.append(row - 1, comment)
vim.api.nvim_win_set_cursor(0, { vim.api.nvim_win_set_cursor(0, {