A tiny plugin for toggling jsdoc checking while preserving the rest of your lsp configuration
jsdoc-demo-vid.mp4
I like JSDoc but not all the time. Needed a way to quickly turn it on or off based on the task I was doing.
- Requires nvim-lspconfig.
tsserver
must be installed and setup - With lazy.nvim
{
'joeldotdias/jsdoc-switch.nvim',
ft = { -- Add or remove filetypes from this section depending on your requirements
'javascript',
'javascriptreact'
},
config = function()
require('jsdoc-switch').setup() -- setup() must be called to create default keymaps
end
}
With packer.nvim
use {
'joeldotdias/jsdoc-switch.nvim',
ft = { -- Add or remove filetypes from this section depending on your requirements
'javascript',
'javascriptreact'
},
config = function()
require('jsdoc-switch').setup() -- setup() must be called to create default keymaps
end
}
The plugin provides you with the following default keymaps
'<leader>jsd' => Toggles JSDoc checking on or off based on the current state
'<leader>jss' => Turns on JSDoc checking
'<leader>jse' => Turns off JSDoc checking
- jsdoc-switch comes with the following defaults
{
--
keys = {
toggle = "<leader>jsd",
checkStart = "<leader>jss",
checkEnd = "<leader>jse"
},
auto_set_keys = true, -- Creates keymaps automatically when plugin is loaded
notify = true, -- Display a notification when jsdoc checking is toggled
}
- Keymaps can be modified by passing them to the setup function
require('jsdoc-switch').setup({
keys = {
checkEnd = "<leader>jse
-- Change the keymaps as you please
}
})
- If you wish to create functions for yourself, set auto_set_keys to false and use the following functions
- toggle()
- startJsdoc()
- stopJsdoc()
- You are also provided with the following commands
- JsdocSwitchToggle
- JsdocSwitchStart
- JsdocSwitchStop
Example config
local switch = require('jsdoc-switch')
switch.setup({
auto_set_keys = false,
notify = false -- Disable notifications or print your custom messages
})
vim.keymap.set('n', '<leader>jds', function()
switch.startJsdoc()
print("Well, hello JSDoc")
end)
vim.keymap.set('n', '<leader>jdt', '<cmd>JsdocSwitchToggle<CR>')
vim.keymap.set('n', '<leader>jdn', function()
vim.cmd("JsdocSwitchStop")
print("Goodbye Jsdoc")
end)
P.S. This is not an elegant plugin in any way but it works. Could be helpful for anyone not wanting to use JSDoc all the time or wanting to try out how it feels.
If this plugin helped you, give it a ⭐ so my grandma thinks I'm cool
A big thank you to numToStr for this great tool which makes docgen so simple