Silence LSP diagnostics with a single click
hush-demo.mp4
lazy.nvim
return {
"mbienkowsk/hush.nvim",
config = {},
keys = {
{ "<leader>h", "<Cmd>Hush<CR>", desc = "Hush" }, -- customize
},
cmd = {
"Hush", "HushAll"
},
}packer.nvim
use({
"mbienkowsk/hush.nvim",
config = function()
require("hush").setup({})
end,
})
vim.keymap.set("n", "<leader>h", "<Cmd>Hush<CR>", { desc = "Hush" }) -- customizevim-plug
Plug 'mbienkowsk/hush.nvim'
lua << EOF
require("hush").setup({})
vim.keymap.set("n", "<leader>h", "<Cmd>Hush<CR>", { desc = "Hush" }) " customize
EOFCurrently, the plugin supports the following diagnostic sources:
- basedpyright
- LuaLS
- clang-tidy
Hush exposes two commands - :Hush and :HushAll. Hush tries to silence the specific warnings emitted by the line using their error codes (if it's not supported in the source, it falls back to HushAll. HushAll disables the offended source for the line (if it's not supported in the source, falls back to Hush.
In order to add support for hushing a source, a subclass of DiagnosticSource has to be added in sources/. Each diagnostic source has to implement 4 things:
comment_positionfield - whether the diagnostic ignore comment is supposed to be above or on the offending linebuild_suppress_all_diagnostics- function returning a string which disables all diagnostics from this source for a given linebuild_suppress_diagnostics- function returning a string which disables the given diagnostics for a given linematches_diagnostic- function that checks if the diagnostic source matches the given diagnostic (some diagnostic sources provide several "source" arguments in the diagnostic based on the context - e.g. lua_ls)
Running tests requires either
to be installed1.
You can then run:
luarocks test --local
# or
bustedOr if you want to run a single test file:
luarocks test spec/path_to_file.lua --local
# or
busted spec/path_to_file.luaIf you see an error like module 'busted.runner' not found:
eval $(luarocks path --no-bin)For this to work you need to have Lua 5.1 set as your default version for
luarocks. If that's not the case you can pass --lua-version 5.1 to all the
luarocks commands above.
Footnotes
-
The test suite assumes that
nluahas been installed using luarocks into~/.luarocks/bin/. ↩