diff --git a/lua/lazyvim/plugins/extras/lang/rust.lua b/lua/lazyvim/plugins/extras/lang/rust.lua index 4e9dff80..c59cd13a 100644 --- a/lua/lazyvim/plugins/extras/lang/rust.lua +++ b/lua/lazyvim/plugins/extras/lang/rust.lua @@ -39,6 +39,41 @@ return { 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 = vim.fn.has("mac") == 1 and extension_path .. "lldb/lib/liblldb.dylib" + or extension_path .. "lldb/lib/liblldb.so" + 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, + }, + } + end, + config = function() end, + }, + -- Correctly setup lspconfig for Rust 🚀 { "neovim/nvim-lspconfig", @@ -50,7 +85,36 @@ return { opts = { servers = { -- Ensure mason installs the server - rust_analyzer = {}, + 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" }, + }, + }, + }, + }, + }, taplo = {}, }, setup = { @@ -63,56 +127,8 @@ return { vim.keymap.set( "n", "dr", "RustDebuggables", { buffer = buffer, desc = "Run Debuggables (Rust)" }) end end) - local mason_registry = require("mason-registry") - -- 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 = vim.fn.has("mac") == 1 and extension_path .. "lldb/lib/liblldb.dylib" - or extension_path .. "lldb/lib/liblldb.so" - local user_rust_tools_opts = require("lazyvim.util").opts("rust-tools.nvim") - local rust_tools_opts = vim.tbl_deep_extend("force", user_rust_tools_opts, { - dap = { - adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path), - }, - 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, - }, - server = vim.tbl_deep_extend("force", opts, { - 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" }, - }, - }, - }, - }, - }), - }) - require("rust-tools").setup(rust_tools_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 })) return true end, taplo = function(_, _) diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index de691941..ea075c07 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -83,7 +83,7 @@ function M.resolve(buffer) local function add(keymap) local keys = Keys.parse(keymap) - if keys[2] == vim.NIL or keys[2] == false then + if keys[2] == false then keymaps[keys.id] = nil else keymaps[keys.id] = keys