add rust plugin to nvim

This commit is contained in:
Alexander Navarro 2025-07-24 13:16:35 -04:00
parent fbcb8598a2
commit 766c50a845
8 changed files with 108 additions and 16 deletions

View file

@ -0,0 +1,35 @@
local rust = vim.cmd.RustLsp
-- Override some LSP mappings
local function opts(desc)
return {
silent = true,
buffer = vim.api.nvim_get_current_buf(),
desc = desc
}
end
vim.keymap.set("n", "<leader>la", function() rust('codeAction') end, opts("Code action"))
vim.keymap.set("n", "<leader>lj", function() rust({ 'renderDiagnostic', "cycle" }) end, opts("Next diagnostic"))
vim.keymap.set("n", "<leader>lk", function() rust({ 'renderDiagnostic', "cycle_prev" }) end, opts("Prev diagnostic"))
vim.keymap.set("n", "<leader>ld", function() rust({ 'renderDiagnostic', "current" }) end, opts("Current diagnostic"))
vim.keymap.set("n", "K", function() rust({ 'hover', 'actions' }) end, opts("Lsp hover"))
vim.keymap.set("n", "J", function() rust("joinLines") end, opts("Keep cursor in column while joining lines"))
vim.keymap.set("v", "J", function() rust({ "moveItem", "down" }) end, opts("Move line down"))
vim.keymap.set("v", "K", function() rust({ "moveItem", "up" }) end, opts("Move line up"))
vim.keymap.set("n", "<leader>lq", function()
vim.ui.select({
{ label = "Expand macro", cmd = { "expandMacro", } },
{ label = "Explain error under cursor", cmd = { "explainError", "current" } },
{ label = "Go to related diagnostic", cmd = { "relatedDiagnostics", } },
{ label = "Open cargo.toml", cmd = { "openCargo", } },
{ label = "Open docs.rs of symbol", cmd = { "openDocs", } },
{ label = "Go to parent module", cmd = { "parentModule", } },
}, { prompt = "RustLsp: ", format_item = function(item) return item.label end }, function(opt)
if opt == nil then return end
rust(opt.cmd)
end)
end, opts("Execute RustLsp action"))

View file

@ -18,6 +18,7 @@
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
"nvim-dap": { "branch": "master", "commit": "5dd4d50f2e6a2eaf9e57fad023d294ef371bda35" }, "nvim-dap": { "branch": "master", "commit": "5dd4d50f2e6a2eaf9e57fad023d294ef371bda35" },
"nvim-dap-view": { "branch": "main", "commit": "390dae6bf67f3342ebb481159932ef0fe54822ba" }, "nvim-dap-view": { "branch": "main", "commit": "390dae6bf67f3342ebb481159932ef0fe54822ba" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" },
"nvim-lint": { "branch": "master", "commit": "b47cbb249351873e3a571751c3fb66ed6369852f" }, "nvim-lint": { "branch": "master", "commit": "b47cbb249351873e3a571751c3fb66ed6369852f" },
"nvim-lspconfig": { "branch": "master", "commit": "b8e7957bde4cbb3cb25a13a62548f7c273b026e9" }, "nvim-lspconfig": { "branch": "master", "commit": "b8e7957bde4cbb3cb25a13a62548f7c273b026e9" },
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
@ -26,10 +27,12 @@
"nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" }, "nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" },
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
"render-markdown": { "branch": "main", "commit": "4a39681990fb515d00dd898de3d7bf2973805f1a" }, "render-markdown": { "branch": "main", "commit": "4a39681990fb515d00dd898de3d7bf2973805f1a" },
"rustaceanvim": { "branch": "master", "commit": "66398662c07d265b226897500ed50eafba3dffb4" },
"smart-splits.nvim": { "branch": "master", "commit": "5ef94ca23b28148187846fc46f10184aad4d17b0" }, "smart-splits.nvim": { "branch": "master", "commit": "5ef94ca23b28148187846fc46f10184aad4d17b0" },
"transfer.nvim": { "branch": "main", "commit": "ab12253c09f83a5b0b6ee108fc131be45abe446a" }, "transfer.nvim": { "branch": "main", "commit": "ab12253c09f83a5b0b6ee108fc131be45abe446a" },
"trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" }, "trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" },
"ts-node-action": { "branch": "master", "commit": "bfaa787cc85d753af3c19245b4142ed727a534b5" }, "ts-node-action": { "branch": "master", "commit": "bfaa787cc85d753af3c19245b4142ed727a534b5" },
"typescript-tools.nvim": { "branch": "master", "commit": "3c501d7c7f79457932a8750a2a1476a004c5c1a9" },
"vim-dadbod": { "branch": "master", "commit": "e95afed23712f969f83b4857a24cf9d59114c2e6" }, "vim-dadbod": { "branch": "master", "commit": "e95afed23712f969f83b4857a24cf9d59114c2e6" },
"vim-dadbod-completion": { "branch": "master", "commit": "a8dac0b3cf6132c80dc9b18bef36d4cf7a9e1fe6" }, "vim-dadbod-completion": { "branch": "master", "commit": "a8dac0b3cf6132c80dc9b18bef36d4cf7a9e1fe6" },
"vim-dadbod-ui": { "branch": "master", "commit": "2900a1617b3df1a48683d872eadbe1101146a49a" }, "vim-dadbod-ui": { "branch": "master", "commit": "2900a1617b3df1a48683d872eadbe1101146a49a" },

View file

@ -31,4 +31,10 @@ vim.keymap.set("n", "<C-j>", "<C-w>j", { desc = "Move to bottom window", silent
vim.keymap.set("n", "<C-k>", "<C-w>k", { desc = "Move to top window", silent = true }) vim.keymap.set("n", "<C-k>", "<C-w>k", { desc = "Move to top window", silent = true })
vim.keymap.set("n", "<C-l>", "<C-w>l", { desc = "Move to right window", silent = true }) vim.keymap.set("n", "<C-l>", "<C-w>l", { desc = "Move to right window", silent = true })
-- stylua: ignore end -- LSP
vim.keymap.set("n", "<leader>lf", vim.lsp.buf.format, { desc = "Format document with LSP", silent = true })
vim.keymap.set("n", "<leader>lj", function() vim.diagnostic.jump({ count = 1 }) end,
{ desc = "Go to next diagnostic", silent = true })
vim.keymap.set("n", "<leader>lk", function() vim.diagnostic.jump({ count = -1 }) end,
{ desc = "Go to next diagnostic", silent = true })

View file

@ -150,15 +150,27 @@ vim.filetype.add({
-- ╭─────────────────────────────────────────────────────────╮ -- ╭─────────────────────────────────────────────────────────╮
-- │ LSP │ -- │ LSP │
-- ╰─────────────────────────────────────────────────────────╯ -- ╰─────────────────────────────────────────────────────────╯
vim.lsp.config("rust-analyzer", {
tools = {
code_actions = {
ui_select_fallback = true
}
}
})
vim.lsp.enable({ vim.lsp.enable({
"bashls", "bashls",
"biome",
"lua_ls", "lua_ls",
"nushell", "nushell",
"pyright", "pyright",
"ruff", "ruff",
"rust_analyzer", -- "rust_analyzer", -- managed by rustacean.nvim
}) })
vim.lsp.inlay_hint.enable(true)
vim.diagnostic.config({ vim.diagnostic.config({
virtual_lines = { current_line = true }, virtual_lines = { current_line = true },
}) })

View file

@ -24,10 +24,22 @@ return {
}, },
}, },
config = function() config = function()
require("dap").adapters.codelldb = { local dap = require("dap")
dap.adapters.codelldb = {
type = "executable", type = "executable",
command = "codelldb", command = "codelldb",
} }
dap.listeners.before['event_initialized']['toggle_lsp_virtual_text'] = function()
vim.lsp.inlay_hint.enable(false)
end
dap.listeners.after['event_terminated']['toggle_lsp_virtual_text'] = function()
vim.lsp.inlay_hint.enable(true)
end
require("nvim-dap-virtual-text").setup()
end, end,
keys = { keys = {
{ {
@ -71,5 +83,16 @@ return {
{ "<leader>dX", function() require("dap").terminate() end, desc = "Terminate" }, { "<leader>dX", function() require("dap").terminate() end, desc = "Terminate" },
{ "<leader>ud", function() require("dap-view").toggle(true) end, desc = "Toggle dap-view" }, { "<leader>ud", function() require("dap-view").toggle(true) end, desc = "Toggle dap-view" },
} }
} },
{
"theHamsta/nvim-dap-virtual-text",
dependencies = { "mfussenegger/nvim-dap", "nvim-treesitter/nvim-treesitter" },
config = function()
require('nvim-dap-virtual-text').setup({
only_first_definition = false,
all_references = true,
virt_text_pos = "eol",
})
end
},
} }

View file

@ -13,18 +13,6 @@ return {
{ "<leader>ls", function() require("ts-node-action").node_action() end, desc = "Node Action" } { "<leader>ls", function() require("ts-node-action").node_action() end, desc = "Node Action" }
} }
}, },
{
-- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = "${3rd}/luv/library", words = { "vim%.uv" } }
},
},
},
{ {
-- allow to reuse the same nvim instance when opening files in the same terminal context -- allow to reuse the same nvim instance when opening files in the same terminal context
"willothy/flatten.nvim", "willothy/flatten.nvim",

View file

@ -0,0 +1,24 @@
return {
{
'mrcjkb/rustaceanvim',
version = '^6', -- Recommended
lazy = false, -- This plugin is already lazy
},
{
-- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = "${3rd}/luv/library", words = { "vim%.uv" } }
},
},
},
{
"pmizio/typescript-tools.nvim",
dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
opts = {},
}
}

View file

@ -149,6 +149,7 @@ return {
{ mode = "n", keys = "<Leader>bl", postkeys = "<Leader>b" }, { mode = "n", keys = "<Leader>bl", postkeys = "<Leader>b" },
{ mode = "n", keys = "<Leader>d", desc = "+Debugger" }, { mode = "n", keys = "<Leader>d", desc = "+Debugger" },
{ mode = "n", keys = "<Leader>dh", postkeys = "<Leader>d" }, { mode = "n", keys = "<Leader>dh", postkeys = "<Leader>d" },
{ mode = "n", keys = "<Leader>dJ", postkeys = "<Leader>d" },
{ mode = "n", keys = "<Leader>dj", postkeys = "<Leader>d" }, { mode = "n", keys = "<Leader>dj", postkeys = "<Leader>d" },
{ mode = "n", keys = "<Leader>dk", postkeys = "<Leader>d" }, { mode = "n", keys = "<Leader>dk", postkeys = "<Leader>d" },
{ mode = "n", keys = "<Leader>dl", postkeys = "<Leader>d" }, { mode = "n", keys = "<Leader>dl", postkeys = "<Leader>d" },