Generate function docs using treesitter
docgen.nvim.webm
Using lazy.nvim
{
"dhananjaylatkar/docgen.nvim",
dependencies = {
{
-- make sure parser for your language is installed
"nvim-treesitter/nvim-treesitter",
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = { "c" },
})
end,
run = ":TSUpdate",
}
},
opts = {
-- USE EMPTY FOR DEFAULT OPTIONS
-- DEFAULTS ARE LISTED BELOW
},
}
You must run require("docgen").setup()
to initialize the plugin.
docgen.nvim comes with following defaults:
-- default doc format for each supported language
{
c = "doxygen", -- "doxygen" or "kernel_doc"
}
Command | Action |
---|---|
:DocGen |
Insert doc for function in scope using configured format |
:DocGen <format> |
Insert doc for function in scope using given format |
You can add support for your language or format easily.
- Create
lua/parsers/<lang>.lua
- Expose
get_doc()
which shall return a table as follows -
{
start_pos = "<start pos of doc>",
ins_pos = "<pos of cursor after inserting>",
comment = "<list of doc comments>"
}
In lua/parsers/<lang>.lua
add else
condition in get_doc()
for doc_format
.