Deprecation of lsp_installer.on_server_ready() #636
Replies: 10 comments 30 replies
-
What will this mean for configs we'd like to be applied to every language server? For example:
Passing this in the
Will we need to manually add these to every language server now? |
Beta Was this translation helpful? Give feedback.
-
How about headless support? is the plan to remove that as well? Because it's still useful either way to have some means of controlling the flow once the installation of a server (or multiple) has completed. A more appropriate name could be |
Beta Was this translation helpful? Give feedback.
-
I have the following setup with if server.name == "rust_analyzer" then
local opts = { ... some other opts ... }
opts.settings = {
["rust-analyzer"] = {
diagnostics = {
disabled = { 'inactive-code' }
}
}
}
require("rust-tools").setup {
server = vim.tbl_deep_extend("force", server:get_default_options(), opts),
}
server:attach_buffers()
require("rust-tools").start_standalone_if_required()
else
server:setup(opts)
end |
Beta Was this translation helpful? Give feedback.
-
I actually kind of liked the Here's how I refactored my init.lua to deal with the deprecation. Hopefully this helps someone. It took me a bit to figure this out for myself. What I had working in the first place, after reading the docs and understanding what require'nvim-lsp-installer'.on_server_ready(function(server)
server:setup({
on_attach = function()
nmap('gD', '<cmd>lua vim.lsp.buf.declaration()<CR>')
nmap('gd', '<cmd>lua vim.lsp.buf.definition()<CR>')
nmap('K', '<cmd>lua vim.lsp.buf.signature_help()<CR>')
nmap('gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
nmap('<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>')
nmap('<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>')
nmap('<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>')
nmap('gr', '<cmd>lua vim.lsp.buf.references()<CR>')
nmap('<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>')
nmap('<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>')
end,
flags = {
debounce_text_changes = 150,
},
capabilities = require('cmp_nvim_lsp').update_capabilities(
vim.lsp.protocol.make_client_capabilities()
)
})
end) To get something like the same behavior (but without auto setup after installing new servers), I refactored to the following, which takes advantage of local lspinstaller = require'nvim-lsp-installer'
local lspconfig = require'lspconfig'
lspinstaller.setup{}
local capabilities = vim.lsp.protocol.make_client_capabilities()
for _, server in ipairs(lspinstaller.get_installed_servers()) do
lspconfig[server.name].setup{
on_attach = function()
nmap('gD', '<cmd>lua vim.lsp.buf.declaration()<CR>')
nmap('gd', '<cmd>lua vim.lsp.buf.definition()<CR>')
nmap('K', '<cmd>lua vim.lsp.buf.signature_help()<CR>')
nmap('gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
nmap('<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>')
nmap('<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>')
nmap('<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>')
nmap('gr', '<cmd>lua vim.lsp.buf.references()<CR>')
nmap('<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>')
nmap('<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>')
end,
flags = {
debounce_text_changes = 150,
},
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
}
end If you have a bunch of custom configurations, I can see why spelling out each server explicitly would be better than doing it all in a loop as I do. |
Beta Was this translation helpful? Give feedback.
-
Is there a way to suppress this suggestion every time nvim is launched? |
Beta Was this translation helpful? Give feedback.
-
This was exactly why I chose to move my config over to this plugin. Is there a way to emulate this functionality with extra config without having to configure every server manually? |
Beta Was this translation helpful? Give feedback.
-
Sorry, but I've been stuck on this migration for hours and I need help. Right now I'm more or less at: use {
"williamboman/nvim-lsp-installer",
"neovim/nvim-lspconfig",
config = function()
require("nvim-lsp-installer").setup {}
local lspconfig = require("lspconfig")
lspconfig.pyright.setup {}
end
}
|
Beta Was this translation helpful? Give feedback.
-
this really seems too much work for not much benefit i think i will be simply using old config and nvim-lsp-installer instead of mason and simply use the old global install method without the installer we had a good run tho thanks for this plugin its sad to see it go this way |
Beta Was this translation helpful? Give feedback.
-
Tjena tjena :) I am looking into migrating my config over to local lsp_installer = require'nvim-lsp-installer'
lsp_installer.on_server_ready(function(server)
local capabilities = require('cmp_nvim_lsp').update_capabilities(
vim.lsp.protocol.make_client_capabilities()
)
local opts = {capabilities = capabilities}
if language_servers[server.name] then
opts = language_servers[server.name].config(opts)
end
server:setup(opts)
end) I've seen some mention of the capabilities part in earlier discussions above, but no clear answers from anybody. I also haven't seen any discussion about the |
Beta Was this translation helpful? Give feedback.
-
A lot of people are having trouble switching from the old method, especially when using custom on_attach hooks. I've got a single commit where I adapted my config to use mason.nvim and I think it should help a lot of people: Main thing to know that you can't see from the diff:
To switch to mason:
The change (diff using Split View is easier to understand): Unfortunately, |
Beta Was this translation helpful? Give feedback.
-
edit(2022-05-11): The deprecation notices that were shown when starting neovim has been temporarily removed. The deprecation still applies, but until a substitute has been implemented and is available these methods will remain and will not print any deprecation warnings.
Deprecation of
lsp_installer.on_server_ready()
Until this point, nvim-lsp-installer has provided a proprietary way of setting up servers, primarily through the suggested
lsp_installer.on_server_ready()
API. This has led to confusion and quite odd interoperability with other LSP plugins.From now on, nvim-lsp-installer will suggest a new, preferred, way of setting up LSP servers where the required interactions with nvim-lsp-installer is reduced to a single line:
Then, to actually set up your servers, you'd do so the "lspconfig way", like so:
In short - make sure to call nvim-lsp-installer's
.setup()
function, then pretend it doesn't exist!This shifts back the responsibility to lspconfig (and other auxiliary plugins such as rust-tools.nvim), which will
consolidate support efforts across the LSP plugins but also making it easier to drive future changes and improvements in neovim's LSP ecosystem.
How does this work?
When calling
require("nvim-lsp-installer").setup {}
, a hook will be registered withlspconfig
. This hook will be invoked every time you set up a server, for example:In this hook, nvim-lsp-installer will enhance the config table with the necessary changes, allowing the builtin LSP client to locate the server executable.
More information
:h nvim-lsp-installer
:h lspconfig
- for how to setup serversDrawbacks
Note that this does come with a few drawbacks, such as:
lspconfig in your config. If you're installing a brand new server, this means you'll have to make changes to your
config and then restart neovim.
installed yet. This may cause you to start seeing warning messages from lspconfig, stating that it's unable to find
the command. To fix this, simply install the missing server(s). Note that you will have to manually trigger a
FileType
(orBufReadPost
) autocmd after installation for lspconfig to attach your currently opened buffers (thisis most easily done by issuing the
:e
command).Example setup
Example new setup, for illustration purposes only (click to expand)
Migrating from
lsp_installer.on_server_ready()
When migrating to the new structure, the only important thing is to make sure to call
require("nvim-lsp-installer").setup {}
before interacting withlspconfig
. Then, simply set up your servers as you would if you were only using lspconfig. There's an example migration PR here, for reference.Beta Was this translation helpful? Give feedback.
All reactions