feat(comment): add comment on on interface method
This commit is contained in:
parent
26207b1928
commit
3cd45c45a3
9 changed files with 91 additions and 13 deletions
|
|
@ -7,25 +7,27 @@
|
|||
|
||||
local ts = require "gopher._utils.ts"
|
||||
local log = require "gopher._utils.log"
|
||||
local u = require "gopher._utils"
|
||||
local comment = {}
|
||||
|
||||
---@param bufnr integer
|
||||
---@param line string
|
||||
---@return string
|
||||
---@dochide
|
||||
local function generate(bufnr)
|
||||
local function generate(bufnr, line)
|
||||
local s_ok, s_res = pcall(ts.get_struct_under_cursor, bufnr)
|
||||
if s_ok then
|
||||
return "// " .. s_res.name .. " "
|
||||
return u.indent(line, s_res.indent) .. "// " .. s_res.name .. " "
|
||||
end
|
||||
|
||||
local f_ok, f_res = pcall(ts.get_func_under_cursor, bufnr)
|
||||
if f_ok then
|
||||
return "// " .. f_res.name .. " "
|
||||
return u.indent(line, f_res.indent) .. "// " .. f_res.name .. " "
|
||||
end
|
||||
|
||||
local i_ok, i_res = pcall(ts.get_interface_under_cursor, bufnr)
|
||||
if i_ok then
|
||||
return "// " .. i_res.name .. " "
|
||||
return u.indent(line, i_res.indent) .. "// " .. i_res.name .. " "
|
||||
end
|
||||
|
||||
local p_ok, p_res = pcall(ts.get_package_under_cursor, bufnr)
|
||||
|
|
@ -38,12 +40,16 @@ end
|
|||
|
||||
function comment.comment()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local cmt = generate(bufnr)
|
||||
log.debug("generated comment: " .. cmt)
|
||||
local lnum = vim.fn.getcurpos()[2]
|
||||
local line = vim.fn.getline(lnum)
|
||||
local cmt = generate(bufnr, line)
|
||||
log.debug("generated comment:", {
|
||||
comment = cmt,
|
||||
line = line,
|
||||
})
|
||||
|
||||
local pos = vim.fn.getcurpos()[2]
|
||||
vim.fn.append(pos - 1, cmt)
|
||||
vim.fn.setpos(".", { 0, pos, #cmt })
|
||||
vim.fn.append(lnum - 1, cmt)
|
||||
vim.fn.setpos(".", { bufnr, lnum, #cmt })
|
||||
vim.cmd "startinsert!"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue