How to prevent starting two instances of rust-analyzer with mason
(LunarVim)?
#174
-
Hello. I used to use rust-tools.nvim with LunarVim. After its deprecation, I switched to rustaceanvim. Due to the fact this plugin wants to manage rust-analyzer startup on its own, I end up having 2 rust-analyzers running: one launched by rustaceanvim and another by either mason or nvim-lspconfig (I'm still not sure who of them is responsible for starting language servers). How can I use this plugin together with LunarVim? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hey 👋 Unfortunately, I can't provide official support for all Neovim distros out there. As you're using LunarVim, the more general solution should work for you. |
Beta Was this translation helpful? Give feedback.
-
Just leaving it here for posterity... I don't use LunarVim, but I had the same happen to me just the other day. Came up with a bunch of solutions most simple of which is just deleting rust_analizer from Mason. However, If you want to keep it, and/or want more flexibility - you can add a condition that prevents certain servers from ever being configured (that's what I did): ---@type MasonLspconfigSettings
require('mason-lspconfig').setup({
---@diagnostic disable-next-line
handlers = { function(server_name)
-- a quick hack to check the list (...if you need a LIST)
local contains = function(table, value)
for index = 1, #table do
if table[index] == value then
return true
end
end
return false
end
-- exclusion list
local exclude = {
-- don't want rust, as I'm using Rustacianvim for it
'rust_analyzer',
}
... Next, you add a condition: ...
if contains(exclude, server_name) then
print('NOPE!')
... A simpler solution, if you only want to override for rust - throw out the top part and just: ...
if server_name == 'rust_analizer' then
print('NOPE!')
... the rest is just your typical stuff that you'd do in mason-lspconfig: ...
else
-- get server settings IF they are specified in server_settings above
local server = server_settings[server_name] or {}
-- get default capabilities and override/extend them IF they are in server_settings
server.capabilities = vim.tbl_deep_extend(
'force',
{},
capabilities,
server.capabilities or {}
)
-- run setup
require('lspconfig')[server_name].setup(server)
end
end, },
}) There might already be a special function or a config option for that in mason-lspconfig, but I was too lazy to check and just made this monstrosity. Hope it helps. |
Beta Was this translation helpful? Give feedback.
Finally, after wasting several hours on this, as a person who isn't familiar enough with lua or LunarVim internals, I came up with the solution! My problem was finding out how to apply LunarVim's LSP keymaps to
rustaceanvim
. Huge thanks to this person's config!~/.config/lvim/config.lua
:rustaceanvim
entry inlvim.plugins
should look like this: