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,41 +39,24 @@ return {
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Correctly setup lspconfig for Rust 🚀
|
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
|
||||||
dependencies = {
|
|
||||||
"simrat39/rust-tools.nvim",
|
"simrat39/rust-tools.nvim",
|
||||||
-- Avoid calling setup twice if user supplies `opts`
|
lazy = true,
|
||||||
config = function() end,
|
opts = function()
|
||||||
},
|
local ok, mason_registry = pcall(require, "mason-registry")
|
||||||
opts = {
|
local adapter ---@type any
|
||||||
servers = {
|
if ok then
|
||||||
-- Ensure mason installs the server
|
|
||||||
rust_analyzer = {},
|
|
||||||
taplo = {},
|
|
||||||
},
|
|
||||||
setup = {
|
|
||||||
rust_analyzer = function(_, opts)
|
|
||||||
require("lazyvim.util").on_attach(function(client, buffer)
|
|
||||||
-- stylua: ignore
|
|
||||||
if client.name == "rust_analyzer" then
|
|
||||||
vim.keymap.set("n", "K", "<cmd>RustHoverActions<cr>", { buffer = buffer, desc = "Hover Actions (Rust)" })
|
|
||||||
vim.keymap.set( "n", "<leader>cR", "<cmd>RustCodeAction<cr>", { buffer = buffer, desc = "Code Action (Rust)" })
|
|
||||||
vim.keymap.set( "n", "<leader>dr", "<cmd>RustDebuggables<cr>", { buffer = buffer, desc = "Run Debuggables (Rust)" })
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
local mason_registry = require("mason-registry")
|
|
||||||
-- rust tools configuration for debugging support
|
-- rust tools configuration for debugging support
|
||||||
local codelldb = mason_registry.get_package("codelldb")
|
local codelldb = mason_registry.get_package("codelldb")
|
||||||
local extension_path = codelldb:get_install_path() .. "/extension/"
|
local extension_path = codelldb:get_install_path() .. "/extension/"
|
||||||
local codelldb_path = extension_path .. "adapter/codelldb"
|
local codelldb_path = extension_path .. "adapter/codelldb"
|
||||||
local liblldb_path = vim.fn.has("mac") == 1 and extension_path .. "lldb/lib/liblldb.dylib"
|
local liblldb_path = vim.fn.has("mac") == 1 and extension_path .. "lldb/lib/liblldb.dylib"
|
||||||
or extension_path .. "lldb/lib/liblldb.so"
|
or extension_path .. "lldb/lib/liblldb.so"
|
||||||
local user_rust_tools_opts = require("lazyvim.util").opts("rust-tools.nvim")
|
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path)
|
||||||
local rust_tools_opts = vim.tbl_deep_extend("force", user_rust_tools_opts, {
|
end
|
||||||
|
return {
|
||||||
dap = {
|
dap = {
|
||||||
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
|
adapter = adapter,
|
||||||
},
|
},
|
||||||
tools = {
|
tools = {
|
||||||
on_initialized = function()
|
on_initialized = function()
|
||||||
|
@ -86,7 +69,28 @@ return {
|
||||||
]])
|
]])
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
server = vim.tbl_deep_extend("force", opts, {
|
}
|
||||||
|
end,
|
||||||
|
config = function() end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Correctly setup lspconfig for Rust 🚀
|
||||||
|
{
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
dependencies = {
|
||||||
|
"simrat39/rust-tools.nvim",
|
||||||
|
-- Avoid calling setup twice if user supplies `opts`
|
||||||
|
config = function() end,
|
||||||
|
},
|
||||||
|
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 = {
|
settings = {
|
||||||
["rust-analyzer"] = {
|
["rust-analyzer"] = {
|
||||||
cargo = {
|
cargo = {
|
||||||
|
@ -110,9 +114,21 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
})
|
taplo = {},
|
||||||
require("rust-tools").setup(rust_tools_opts)
|
},
|
||||||
|
setup = {
|
||||||
|
rust_analyzer = function(_, opts)
|
||||||
|
require("lazyvim.util").on_attach(function(client, buffer)
|
||||||
|
-- stylua: ignore
|
||||||
|
if client.name == "rust_analyzer" then
|
||||||
|
vim.keymap.set("n", "K", "<cmd>RustHoverActions<cr>", { buffer = buffer, desc = "Hover Actions (Rust)" })
|
||||||
|
vim.keymap.set( "n", "<leader>cR", "<cmd>RustCodeAction<cr>", { buffer = buffer, desc = "Code Action (Rust)" })
|
||||||
|
vim.keymap.set( "n", "<leader>dr", "<cmd>RustDebuggables<cr>", { buffer = buffer, desc = "Run Debuggables (Rust)" })
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
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,
|
||||||
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