feat: improved lsp setup for nvim > 0.11
The aim of this change is to provide a much clearer distinction between how servers are installed & configured (either directly via Mason or manually). This is a slight alternative to this excellent PR for LSP configuration for neovim > 0.11 onwards.
Since the new mason-lspconfig changes enable all servers installed via Mason by default, this might cause confusion for newcomers around server enable if they had a language server installed manually but wanted to re-use the default nvim-lspconfig configs.
Furthermore, not all language servers might be available on Mason for download - however they might already have default configs available on nvim-lspconfig for re-use (example) or have neither available on Mason and nvim-lspconfig.
I'm hoping another benefit of this change is that it should also aid in reducing burden on the mason & nvim-lspconfig maintainers when it comes to answering these specific kind of lsp questions.
As always, I'm open to any feedback here. I'm not too fussed if the above linked PR gets merged over this, but wanted to float this idea by the maintainers and community to gather any & all feedback.
Cheers! 🙂
Minor Changes:
- Commented and preserved the capabilities step for educational purposes only;
- Auto formatter might have formatted some code, which I quite like tbh . Happy to revert it if needed.
Just an FYI, I have ported this fixes to my kickstart base config. after adding the loop to call lsp.config load time went to 200ms just on the lspconfig
Just an FYI, I have ported this fixes to my kickstart base config. after adding the loop to call
lsp.configload time went to 200ms just on the lspconfig
It's something I'm experiencing with lots of LSPs installed via Mason with automatic_enable = true. More than half of my startup time goes to enable the LSPs. I wonder why is it so expensive, though.
Just an FYI, I have ported this fixes to my kickstart base config. after adding the loop to call
lsp.configload time went to 200ms just on the lspconfigIt's something I'm experiencing with lots of LSPs installed via Mason with
automatic_enable = true. More than half of my startup time goes to enable the LSPs. I wonder why is it so expensive, though.
I also noticed that, right now loading LSP at VeryLazy event is enough to fix it.
-- Main LSP Configuration
'neovim/nvim-lspconfig',
event = 'VeryLazy',
cmd = { 'LspInfo', 'LspInstall', 'LspUninstall' },
Just an FYI, I have ported this fixes to my kickstart base config. after adding the loop to call
lsp.configload time went to 200ms just on the lspconfigIt's something I'm experiencing with lots of LSPs installed via Mason with
automatic_enable = true. More than half of my startup time goes to enable the LSPs. I wonder why is it so expensive, though.I also noticed that, right now loading LSP at
VeryLazyevent is enough to fix it.-- Main LSP Configuration 'neovim/nvim-lspconfig', event = 'VeryLazy', cmd = { 'LspInfo', 'LspInstall', 'LspUninstall' },
Works great! Do you want to open a PR maybe? Or is it a temporary solution that shouldn't really belong?
Overal I like the idea of separating the mason and other servers.
However this PR is dealing with mason-lspconfig 2.0 rather than nvim 0.11 and it does more than it says.
The idea of separating mason and other servers may be a subject of another PR.
I recommend #1663 over this one as it does exactly what it says and does it correctly.
Just an FYI, I have ported this fixes to my kickstart base config. after adding the loop to call
lsp.configload time went to 200ms just on the lspconfigIt's something I'm experiencing with lots of LSPs installed via Mason with
automatic_enable = true. More than half of my startup time goes to enable the LSPs. I wonder why is it so expensive, though.I also noticed that, right now loading LSP at
VeryLazyevent is enough to fix it.-- Main LSP Configuration 'neovim/nvim-lspconfig', event = 'VeryLazy', cmd = { 'LspInfo', 'LspInstall', 'LspUninstall' },
Unfortunately, this only seems to work if the LSP servers are already installed and configured.
I tried this with a fresh nvim install and for some reason, no servers would be installed until I removed those two lines.
I manually patched this change into my modular kickstart config and it seems to fix the issue I was having with my configs for LSPs not propagating. I was also wondering how to install non-mason LSPs. This PR addresses both my questions, thank you!
Unfortunately, this only seems to work if the LSP servers are already installed and configured.
I tried this with a fresh
nviminstall and for some reason, no servers would be installed until I removed those two lines.
Yes, it's a known issue https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim/issues/39
The workaround is
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
vim.api.nvim_command('MasonToolsInstall')
This helped me fix my issues with LSP configs not being ran. Hope this gets merged, so that fresh people don't have to suffer and flail around as I did.