mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-15 11:54:36 +02:00
feat(rust): refactor to allow easy user customization and keymaps
This commit is contained in:
parent
61e3ce8cdc
commit
a46d47653e
2 changed files with 68 additions and 52 deletions
|
@ -39,6 +39,41 @@ return {
|
||||||
end,
|
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 🚀
|
-- Correctly setup lspconfig for Rust 🚀
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
|
@ -50,7 +85,36 @@ return {
|
||||||
opts = {
|
opts = {
|
||||||
servers = {
|
servers = {
|
||||||
-- Ensure mason installs the server
|
-- 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 = {},
|
||||||
},
|
},
|
||||||
setup = {
|
setup = {
|
||||||
|
@ -63,56 +127,8 @@ return {
|
||||||
vim.keymap.set( "n", "<leader>dr", "<cmd>RustDebuggables<cr>", { buffer = buffer, desc = "Run Debuggables (Rust)" })
|
vim.keymap.set( "n", "<leader>dr", "<cmd>RustDebuggables<cr>", { buffer = buffer, desc = "Run Debuggables (Rust)" })
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
local mason_registry = require("mason-registry")
|
local rust_tools_opts = require("lazyvim.util").opts("rust-tools.nvim")
|
||||||
-- rust tools configuration for debugging support
|
require("rust-tools").setup(vim.tbl_deep_extend("force", rust_tools_opts or {}, { server = opts }))
|
||||||
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)
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
taplo = function(_, _)
|
taplo = function(_, _)
|
||||||
|
|
|
@ -83,7 +83,7 @@ function M.resolve(buffer)
|
||||||
|
|
||||||
local function add(keymap)
|
local function add(keymap)
|
||||||
local keys = Keys.parse(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
|
keymaps[keys.id] = nil
|
||||||
else
|
else
|
||||||
keymaps[keys.id] = keys
|
keymaps[keys.id] = keys
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue