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

View File

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