feat(lang) replace rust-tools.nvim with rustacean.nvim - fixes #2113 (#2198)

* feat(lang) - move to rustacean.nvim, fixes #2113

* update rustacean plugin

* PR comment for lsp settings
This commit is contained in:
Andreas Gerlach 2024-03-07 11:42:23 +01:00 committed by GitHub
parent a8eeb1b75d
commit 66bf7525e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,9 +25,8 @@ return {
{ {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
opts = function(_, opts) opts = function(_, opts)
if type(opts.ensure_installed) == "table" then opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "ron", "rust", "toml" }) vim.list_extend(opts.ensure_installed, { "ron", "rust", "toml" })
end
end, end,
}, },
@ -36,51 +35,56 @@ return {
"williamboman/mason.nvim", "williamboman/mason.nvim",
optional = true, optional = true,
opts = function(_, opts) opts = function(_, opts)
if type(opts.ensure_installed) == "table" then opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "codelldb" }) vim.list_extend(opts.ensure_installed, { "codelldb" })
end
end, end,
}, },
{ {
"simrat39/rust-tools.nvim", "mrcjkb/rustaceanvim",
lazy = true, version = '^4', -- Recommended
opts = function() ft = { "rust" },
local ok, mason_registry = pcall(require, "mason-registry") opts = {
local adapter ---@type any server = {
if ok then on_attach = function(client, bufnr)
-- rust tools configuration for debugging support -- register which-key mappings
local codelldb = mason_registry.get_package("codelldb") local wk = require("which-key")
local extension_path = codelldb:get_install_path() .. "/extension/" wk.register({
local codelldb_path = extension_path .. "adapter/codelldb" ["<leader>cR"] = { function() vim.cmd.RustLsp("codeAction") end, "Code Action" },
local liblldb_path = "" ["<leader>dr"] = { function() vim.cmd.RustLsp("debuggables") end, "Rust debuggables" },
if vim.loop.os_uname().sysname:find("Windows") then }, { mode = "n", buffer = bufnr })
liblldb_path = extension_path .. "lldb\\bin\\liblldb.dll" end,
elseif vim.fn.has("mac") == 1 then default_settings = {
liblldb_path = extension_path .. "lldb/lib/liblldb.dylib" -- rust-analyzer language server configuration
else ["rust-analyzer"] = {
liblldb_path = extension_path .. "lldb/lib/liblldb.so" cargo = {
end allFeatures = true,
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path) loadOutDirsFromCheck = true,
end runBuildScripts = true,
return { },
dap = { -- Add clippy lints for Rust.
adapter = adapter, checkOnSave = {
}, allFeatures = true,
tools = { command = "clippy",
on_initialized = function() extraArgs = { "--no-deps" },
vim.cmd([[ },
augroup RustLSP procMacro = {
autocmd CursorHold *.rs silent! lua vim.lsp.buf.document_highlight() enable = true,
autocmd CursorMoved,InsertEnter *.rs silent! lua vim.lsp.buf.clear_references() ignored = {
autocmd BufEnter,CursorHold,InsertLeave *.rs silent! lua vim.lsp.codelens.refresh() ["async-trait"] = { "async_trait" },
augroup END ["napi-derive"] = { "napi" },
]]) ["async-recursion"] = { "async_recursion" },
end, },
},
},
}, },
} }
end, },
config = function() end, config = function(_, opts)
vim.g.rustaceanvim = vim.tbl_deep_extend("force",
{},
opts or {})
end
}, },
-- Correctly setup lspconfig for Rust 🚀 -- Correctly setup lspconfig for Rust 🚀
@ -88,37 +92,7 @@ return {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
opts = { opts = {
servers = { servers = {
-- Ensure mason installs the server rust_analyzer = {},
rust_analyzer = {
keys = {
{ "K", "<cmd>RustHoverActions<cr>", desc = "Hover Actions (Rust)" },
{ "<leader>cR", "<cmd>RustCodeAction<cr>", desc = "Code Action (Rust)" },
{ "<leader>dr", "<cmd>RustDebuggables<cr>", desc = "Run Debuggables (Rust)" },
},
settings = {
["rust-analyzer"] = {
cargo = {
allFeatures = true,
loadOutDirsFromCheck = true,
runBuildScripts = true,
},
-- Add clippy lints for Rust.
checkOnSave = {
allFeatures = true,
command = "clippy",
extraArgs = { "--no-deps" },
},
procMacro = {
enable = true,
ignored = {
["async-trait"] = { "async_trait" },
["napi-derive"] = { "napi" },
["async-recursion"] = { "async_recursion" },
},
},
},
},
},
taplo = { taplo = {
keys = { keys = {
{ {
@ -136,9 +110,7 @@ return {
}, },
}, },
setup = { setup = {
rust_analyzer = function(_, opts) rust_analyzer = function()
local rust_tools_opts = require("lazyvim.util").opts("rust-tools.nvim")
require("rust-tools").setup(vim.tbl_deep_extend("force", rust_tools_opts or {}, { server = opts }))
return true return true
end, end,
}, },
@ -148,13 +120,12 @@ return {
{ {
"nvim-neotest/neotest", "nvim-neotest/neotest",
optional = true, optional = true,
dependencies = { opts = function(_, opts)
"rouge8/neotest-rust", opts.adapters = opts.adapters or {}
}, vim.list_extend(opts.adapters, {
opts = { require('rustaceanvim.neotest'),
adapters = { })
["neotest-rust"] = {}, end
},
},
}, },
} }