Use rustaceanvim rather than defunct rust-tools

This commit is contained in:
ViViDboarder 2024-10-28 16:18:12 -07:00
parent 29e936904d
commit 54da69cd40
3 changed files with 32 additions and 33 deletions

View File

@ -155,9 +155,9 @@
"branch": "master",
"commit": "2d9b06177a975543726ce5c73fca176cedbffe9d"
},
"rust-tools.nvim": {
"rustaceanvim": {
"branch": "master",
"commit": "676187908a1ce35ffcd727c654ed68d851299d3e"
"commit": "e1f9464d9e1addeccb170eb7968471966965f5a3"
},
"sg.nvim": {
"branch": "master",

View File

@ -340,8 +340,21 @@ return {
-- Rust analyzer
{
"https://github.com/simrat39/rust-tools.nvim",
"https://github.com/mrcjkb/rustaceanvim",
version = "^5",
-- Already loads on ft
lazy = false,
ft = { "rust" },
init = function()
local lsp = require("plugins.lsp")
vim.g.rustaceanvim = {
server = {
capabilities = lsp.merged_capabilities(),
on_attach = lsp.get_default_attach(),
},
}
end,
enabled = vim.fn.has("nvim-0.10") == 1,
},
-- Better display of lsp diagnostics

View File

@ -36,7 +36,7 @@ function M.config_lsp_ui()
end)
end
local function get_default_attach(override_capabilities)
function M.get_default_attach(override_capabilities)
return function(client, bufnr)
-- Allow overriding capabilities to avoid duplicate lsps with capabilities
@ -162,7 +162,7 @@ local function get_default_attach(override_capabilities)
end
end
local function merged_capabilities()
function M.merged_capabilities()
-- Maybe update capabilities
local capabilities = nil
utils.try_require("cmp-nvim-lsp", function(cmp_nvim_lsp)
@ -174,8 +174,8 @@ end
function M.config_lsp()
utils.try_require("lspconfig", function(lsp_config)
local capabilities = merged_capabilities()
local default_attach = get_default_attach()
local capabilities = M.merged_capabilities()
local default_attach = M.get_default_attach()
local default_setup = { capabilities = capabilities, on_attach = default_attach }
local maybe_setup = function(config, options)
@ -205,22 +205,10 @@ function M.config_lsp()
})
-- Set up rust analyzer (preferred) or rls
-- TODO: Remove rls and all configuration for it when all machines are up to date
if vim.fn.executable("rust-analyzer") == 1 then
-- Prefer rust-tools, if present
utils.try_require("rust-tools", function(rust_tools)
rust_tools.setup({
server = {
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({
-- NOTE: For version 0.10 or higher, rustaceanvim is initialized in ftconfig
-- Maybe all lsp configs should be set up as part of their ftconfig
if vim.fn.has("nvim-0.10") == 1 then
maybe_setup(lsp_config.rust_analyzer, {
capabilities = capabilities,
on_attach = default_attach,
settings = {
@ -231,8 +219,6 @@ function M.config_lsp()
},
},
})
end)
else
maybe_setup(lsp_config.rls, default_setup)
end