The LSP makes me feel extremely under siege, especially since seemingly every LSP server insists on throwing hundreds of totally useless style warnings.
I would really like the diagnostics to be toggle-able, defaulting to OFF, but for the LSP server to start running in the background when I start neovim whether I use the diagnostics or not.
The current API doesn’t seem to provide particularly great ways of doing this… I can probably hobble something together with the documented functions, but it won’t be pretty… and in my early experiments with this I have utterly failed to get neovim to start with diagnostics off.
autocmd BufEnter * lua vim.lsp.diagnostic.disable() will probably do what you want. You can map a key to lua vim.lsp.diagnostic.enable()
Note, there is no turning diagnostics on or off, only turning the display of diagnostics on/off. Most servers send diagnostics regardless of if we report the diagnostic capability. You should also look into configuring your language server to remove style warnings you do not want.
The more modern (non-deprecated) way of doing this seems to be lua vim.diagnostic.hide(). If I do that manually, it works great. However, if I do that with the vimrc setting above:
autocmd BufEnter * lua vim.diagnostic.hide()
it does not work! Do I need to use a different trigger-event now? Did I do something wrong?
vim.diagnostic.disable() will disable diagnostics globally. Likewise, enable() enables them globally. Pass a buffer number as the first argument to either function to disable/enable diagnostics only for the given buffer (0 means “current buffer”).
All of this (and more) is mentioned in the docs. :h vim.diagnostic
Edit: Never mind, I read :h deprecated wrong. You can disregard my message below. Thanks a lot again, everything works great now.
Thanks, using vim.diagnostic.disable() works perfectly. What set me on the wrong path was that (I think) the :h deprecated help is wrong:
*vim.lsp.diagnostic.clear()* Use |vim.diagnostic.hide()| instead.
*vim.lsp.diagnostic.disable()*
*vim.lsp.diagnostic.display()* Use |vim.diagnostic.show()| instead.
*vim.lsp.diagnostic.enable()*