From 0333a7e335095f669abf0dad90d50014782c732b Mon Sep 17 00:00:00 2001 From: Andreas Gerlach Date: Sat, 16 Dec 2023 10:15:36 +0100 Subject: [PATCH] feat(lang) - move to rustacean.nvim, fixes #2113 --- lua/lazyvim/plugins/extras/lang/rust.lua | 115 +++++++++-------------- 1 file changed, 45 insertions(+), 70 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/rust.lua b/lua/lazyvim/plugins/extras/lang/rust.lua index 1e6e0594..68125552 100644 --- a/lua/lazyvim/plugins/extras/lang/rust.lua +++ b/lua/lazyvim/plugins/extras/lang/rust.lua @@ -45,44 +45,50 @@ return { }, { - "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 = "^3", -- Recommended + ft = { "rust" }, + opts = { + server = { + on_attach = function(client, bufnr) + -- register which-key mappings + local wk = require("which-key") + wk.register({ + ["cR"] = { function() vim.cmd.RustLsp("codeAction") end, "Code Action" }, + ["dr"] = { function() vim.cmd.RustLsp("debuggables") end, "Rust debuggables" }, + }, { mode = "n", buffer = bufnr }) + end, + 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 🚀 @@ -90,37 +96,7 @@ return { "neovim/nvim-lspconfig", opts = { servers = { - -- Ensure mason installs the server - rust_analyzer = { - keys = { - { "K", "RustHoverActions", desc = "Hover Actions (Rust)" }, - { "cR", "RustCodeAction", desc = "Code Action (Rust)" }, - { "dr", "RustDebuggables", 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 = { { @@ -138,9 +114,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, }, @@ -159,4 +133,5 @@ return { }, }, }, + }