Switch from rls to rust-analyzer and from rust.vim to rust-tools.nvim

This includes some transition support for both rls and rust-analyzer
that should eventually be removed.
This commit is contained in:
ViViDboarder 2023-06-13 14:59:37 -07:00
parent b0e8fe7743
commit 21de929b35
3 changed files with 40 additions and 13 deletions

View File

@ -75,7 +75,7 @@ function install_language_servers() {
# Rust # Rust
if want_lang rust ;then if want_lang rust ;then
maybe_run rustup component add rls rustfmt rust-analysis rust-src clippy rustfmt maybe_run rustup component add rustfmt rust-analysis rust-src clippy rust-analyzer
fi fi
# Go # Go

View File

@ -269,6 +269,12 @@ use({
requires = "neovim/nvim-lspconfig", requires = "neovim/nvim-lspconfig",
}) })
-- Rust analyzer
use({
"simrat39/rust-tools.nvim",
disable = vim.fn.has("nvim-0.7.0") ~= 1,
})
-- Better display of lsp diagnostics -- Better display of lsp diagnostics
-- TODO: Pin < 0.7 version -- TODO: Pin < 0.7 version
use({ use({
@ -441,7 +447,6 @@ use({
-- Filetypes -- Filetypes
use("ViViDboarder/vim-forcedotcom") use("ViViDboarder/vim-forcedotcom")
use("rust-lang/rust.vim")
use("hsanson/vim-android") use("hsanson/vim-android")
use({ use({
"sheerun/vim-polyglot", "sheerun/vim-polyglot",

View File

@ -254,17 +254,39 @@ function M.config_lsp()
lsp_config.bashls.setup(default_setup) lsp_config.bashls.setup(default_setup)
lsp_config.gopls.setup(default_setup) lsp_config.gopls.setup(default_setup)
lsp_config.pyright.setup(default_setup) lsp_config.pyright.setup(default_setup)
lsp_config.rls.setup({
capabilities = capabilities, -- Set up rust analyzer (preferred) or rls
on_attach = default_attach, -- TODO: Remove rls and all configuration for it when all machines are up to date
settings = { if vim.fn.executable("rust-analyzer") == 1 then
rust = { -- Prefer rust-tools, if present
build_on_save = false, utils.try_require("rust-tools", function(rust_tools)
all_features = true, rust_tools.setup({
unstable_features = true, capabilities = capabilities,
}, on_attach = function(client, bufnr)
}, default_attach(client, bufnr)
}) -- TODO: override some bindings from rust-tools
-- Eg. rust_tools.hover_actions.hover_actions or rt.code_action_group.code_action_group
end,
})
end, function()
lsp_config.rust_analyzer.setup({
capabilities = capabilities,
on_attach = default_attach,
settings = {
["rust-analyzer"] = {
cargo = {
features = "all",
},
},
},
})
end)
else
lsp_config.rls.setup({
capabilities = capabilities,
on_attach = default_attach,
})
end
-- Configure neovim dev for when sumneko_lua is installed -- Configure neovim dev for when sumneko_lua is installed
utils.try_require("neodev", function(neodev) utils.try_require("neodev", function(neodev)