* idk how good this idea is * this could be working but i still cant figure out how to run it * ignore tags that mini.doc gens, but why? * chore(taskfile): force exiting after tests because i got infinit ci * chore(ci): add more nvim versions to run on * chore: update taskfile * feat: add docs generator * docs: its only begining * refactor: update docgen script * docs: write some more * docs(config): update * docs: update readme * language * hope it would work * what about that? * maybe this would work? * update md * upd * WHY DOESNT IT WORKING * idk by but 0.9.3 just fails the ci, so i deleted it from suite * again update, why does markdown not work in embeded html * maybe it can help? * upd * again update * kinda fix * fix: formatting * again some updating * some readme updating * fix, this shouldnt be in repo * i finnaly undertood how to fix this fking skill issue * fix(struct_tags): typo * refactor(docs): change the order in generated file * docs: install deps * refactor(scripts): rename doc-gen script * docs(impl): write docs * docs(dap): add doc * stylua . * docs(struct_tags): add doc * docs(gotests): add docs * docs(iferr): add docs * docs(comment): add doc * update CONTRIBUTING.md * docs(README): talk about `develop` branch * docs: update README.md
55 lines
1.4 KiB
Lua
55 lines
1.4 KiB
Lua
---@toc_entry Generate comments
|
|
---@tag gopher.nvim-comments
|
|
---@usage Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line.
|
|
---@text This module provides a way to generate comments for Go code.
|
|
|
|
local function generate(row, col)
|
|
local ts_utils = require "gopher._utils.ts"
|
|
local comment, ns = nil, nil
|
|
|
|
ns = ts_utils.get_package_node_at_pos(row, col, nil, false)
|
|
if ns ~= nil then
|
|
comment = "// Package " .. ns.name .. " provides " .. ns.name
|
|
return comment, ns
|
|
end
|
|
|
|
ns = ts_utils.get_struct_node_at_pos(row, col, nil, false)
|
|
if ns ~= nil then
|
|
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
|
return comment, ns
|
|
end
|
|
|
|
ns = ts_utils.get_func_method_node_at_pos(row, col, nil, false)
|
|
if ns ~= nil then
|
|
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
|
return comment, ns
|
|
end
|
|
|
|
ns = ts_utils.get_interface_node_at_pos(row, col, nil, false)
|
|
if ns ~= nil then
|
|
comment = "// " .. ns.name .. " " .. ns.type .. " "
|
|
return comment, ns
|
|
end
|
|
|
|
return "// ", {}
|
|
end
|
|
|
|
return function()
|
|
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
local comment, ns = generate(row + 1, col + 1)
|
|
|
|
vim.api.nvim_win_set_cursor(0, {
|
|
ns.dim.s.r,
|
|
ns.dim.s.c,
|
|
})
|
|
|
|
---@diagnostic disable-next-line: param-type-mismatch
|
|
vim.fn.append(row - 1, comment)
|
|
|
|
vim.api.nvim_win_set_cursor(0, {
|
|
ns.dim.s.r,
|
|
#comment + 1,
|
|
})
|
|
|
|
vim.cmd [[startinsert!]]
|
|
end
|