Dynamic, treesitter-based JavaScript annotation generator for neovim, following JSDoc conventions.
This plugin analyzes the tree provided by treesitter and generates JSDoc annotations for JavaScript code snippet under the cursor. In order to typing annotation descriptions more efficiently, the generated annotation are LuaSnip dynamic snippets. The default or user-defined key-bindings for jumping through LuaSnip snippets will also work for snippets generated by this plugin.
Currently the plugin is most useful for generating annotation for functions. In case you have any suggestions feel free to open an issue.
This plugin depends on tree-sitter and luasnip so in addition to this plugin you also need to install these dependencies.
Installation via packer:
use {
"ramhejazi/jsdoc.nvim",
config = function()
require('jsdoc.nvim').setup {}
end,
}
Calling the setup
function is optional.
The function creates an user command named JSDoc
.
-- Defining key binding for calling the `generate` function which subsequently
-- generates jsdoc snippets
vim.keymap.set({ "n" }, "<leader>o", function()
local jsdoc_nvim = require('jsdoc_nvim')
-- is the current context JavaScript?
if jsdoc_nvim.is_context_javascript() then
jsdoc_nvim.generate();
else
-- optionally run another doc generator
-- require('neogen').generate()
end
end, { silent = true })
-- Defining key-bindings for luasnip (optional)
local ls = require('luasnip')
vim.keymap.set({ "i" }, "<C-L>", function() ls.expand() end, { silent = true })
vim.keymap.set({ "i", "s" }, "<C-J>", function() ls.jump(1) end, { silent = true })
vim.keymap.set({ "i", "s" }, "<C-K>", function() ls.jump(-1) end, { silent = true })