mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-02-04 08:41:43 +05:30
feat(neovim-rust): Rust LSP, debugging, testing and keymaps
- `rustaceanvim` for LSP config - Rust ft specific keymaps in `after/ftplugin` - `nvim-dap` for Rust debugging with codelldb - `rustaceanvim.neotest` for Rust testing - `rcasia/neotest-bash` for Bash testing - Better keymaps for running tests - Inlay hint UI improvements
This commit is contained in:
@@ -1,23 +1,10 @@
|
|||||||
-- TODO: Map all native Nvim 0.11 LSP commands to corresponding rustaceanvim ones
|
|
||||||
-- grn -> Rename
|
|
||||||
-- grr -> References
|
|
||||||
-- gri -> Implementation
|
|
||||||
-- gO -> document_symbol
|
|
||||||
-- gra -> code_action
|
|
||||||
-- Mine
|
|
||||||
-- F2 -> Rename
|
|
||||||
-- gD -> Go to definition
|
|
||||||
-- <leader>cr -> References
|
|
||||||
-- <leader>co -> document_symbol
|
|
||||||
|
|
||||||
if pcall(require, "rustaceanvim") then
|
if pcall(require, "rustaceanvim") then
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
vim.keymap.set("n", "gC", "<cmd>RustLsp openCargo<cr>", { desc = "Open Cargo.toml", buffer = bufnr })
|
||||||
vim.keymap.set("n", "<C-.>", function()
|
vim.keymap.set("n", "<leader>rm", "<cmd>RustLsp expandMacro<cr>", { desc = "Expand Macro", buffer = bufnr })
|
||||||
vim.cmd.RustLsp("codeAction")
|
vim.keymap.set("n", "<leader>rp", "<cmd>RustLsp parentModule<cr>", { desc = "Parent Module", buffer = bufnr })
|
||||||
end, { silent = true, buffer = bufnr })
|
vim.keymap.set("n", "<leader>rJ", "<cmd>RustLsp joinLines<cr>", { desc = "Join Lines", buffer = bufnr })
|
||||||
|
vim.keymap.set("n", "<leader>rh", "<cmd>RustLsp openDocs<cr>", { desc = "Open docs.rs Documentation" })
|
||||||
vim.keymap.set("n", "K", function()
|
vim.keymap.set("n", "<leader>rM", "<cmd>RustLsp view mir<cr>", { desc = "View Mid-Level IR", buffer = bufnr })
|
||||||
vim.cmd.RustLsp({ "hover", "actions" })
|
vim.keymap.set("n", "<leader>rH", "<cmd>RustLsp view hir<cr>", { desc = "View High-Level IR", buffer = bufnr })
|
||||||
end, { silent = true, buffer = bufnr })
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ vim.api.nvim_create_autocmd("LspAttach", {
|
|||||||
|
|
||||||
-- Native lsp inline virtual text / inlay hints
|
-- Native lsp inline virtual text / inlay hints
|
||||||
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
|
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
|
||||||
vim.lsp.inlay_hint.enable()
|
vim.lsp.inlay_hint.enable(true)
|
||||||
|
vim.api.nvim_set_hl(0, "LspInlayHint", { fg = "#5c7086", bg = "NONE" })
|
||||||
|
|
||||||
map("<leader>ch", function()
|
map("<leader>ch", function()
|
||||||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
|
||||||
|
|||||||
@@ -1 +1,172 @@
|
|||||||
return {}
|
return {
|
||||||
|
"mfussenegger/nvim-dap",
|
||||||
|
dependencies = {
|
||||||
|
-- Creates a beautiful debugger UI
|
||||||
|
"rcarriga/nvim-dap-ui",
|
||||||
|
|
||||||
|
-- Required dependency for nvim-dap-ui
|
||||||
|
"nvim-neotest/nvim-nio",
|
||||||
|
|
||||||
|
-- Auto-installs debugger adapters
|
||||||
|
"mason-org/mason.nvim",
|
||||||
|
"jay-babu/mason-nvim-dap.nvim",
|
||||||
|
|
||||||
|
-- Shows variable values inline as virtual text
|
||||||
|
"theHamsta/nvim-dap-virtual-text",
|
||||||
|
},
|
||||||
|
keys = {
|
||||||
|
{
|
||||||
|
"<F5>",
|
||||||
|
function()
|
||||||
|
require("dap").continue()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Start/Continue",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>Ds",
|
||||||
|
function()
|
||||||
|
require("dap").continue()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Start/Continue",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<F11>",
|
||||||
|
function()
|
||||||
|
require("dap").step_into()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Step Into",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>Di",
|
||||||
|
function()
|
||||||
|
require("dap").step_into()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Step Into",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<F10>",
|
||||||
|
function()
|
||||||
|
require("dap").step_over()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Step Over",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>Do",
|
||||||
|
function()
|
||||||
|
require("dap").step_over()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Step Over",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<S-F11>",
|
||||||
|
function()
|
||||||
|
require("dap").step_out()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Step Out",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>DO",
|
||||||
|
function()
|
||||||
|
require("dap").step_out()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Step Out",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<F9>",
|
||||||
|
function()
|
||||||
|
require("dap").toggle_breakpoint()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Toggle Breakpoint",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>Db",
|
||||||
|
function()
|
||||||
|
require("dap").toggle_breakpoint()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Toggle Breakpoint",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>DB",
|
||||||
|
function()
|
||||||
|
require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))
|
||||||
|
end,
|
||||||
|
desc = "Debug: Set Conditional Breakpoint",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>Dt",
|
||||||
|
function()
|
||||||
|
require("dapui").toggle()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Toggle UI",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"<leader>Dl",
|
||||||
|
function()
|
||||||
|
require("dap").run_last()
|
||||||
|
end,
|
||||||
|
desc = "Debug: Run Last Configuration",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
local dap = require("dap")
|
||||||
|
local dapui = require("dapui")
|
||||||
|
|
||||||
|
-- optional
|
||||||
|
require("mason-nvim-dap").setup({
|
||||||
|
automatic_installation = true,
|
||||||
|
handlers = {},
|
||||||
|
ensure_installed = {
|
||||||
|
"codelldb",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Dap UI setup
|
||||||
|
dapui.setup({
|
||||||
|
icons = { expanded = "▾", collapsed = "▸", current_frame = "*" },
|
||||||
|
controls = {
|
||||||
|
icons = {
|
||||||
|
pause = "⏸",
|
||||||
|
play = "▶",
|
||||||
|
step_into = "⏎",
|
||||||
|
step_over = "⏭",
|
||||||
|
step_out = "⏮",
|
||||||
|
step_back = "b",
|
||||||
|
run_last = "▶▶",
|
||||||
|
terminate = "⏹",
|
||||||
|
disconnect = "⏏",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Automatically open/close DAP UI
|
||||||
|
dap.listeners.after.event_initialized["dapui_config"] = dapui.open
|
||||||
|
dap.listeners.before.event_terminated["dapui_config"] = dapui.close
|
||||||
|
dap.listeners.before.event_exited["dapui_config"] = dapui.close
|
||||||
|
|
||||||
|
-- Setup virtual text to show variable values inline
|
||||||
|
require("nvim-dap-virtual-text").setup()
|
||||||
|
|
||||||
|
-- Setup Rust & React DAPs here
|
||||||
|
dap.adapters.codelldb = {
|
||||||
|
type = "server",
|
||||||
|
port = "${port}",
|
||||||
|
executable = {
|
||||||
|
command = vim.fn.exepath("codelldb"),
|
||||||
|
args = { "--port", "${port}" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
dap.configurations.rust = {
|
||||||
|
{
|
||||||
|
name = "Launch file",
|
||||||
|
type = "codelldb",
|
||||||
|
request = "launch",
|
||||||
|
program = function()
|
||||||
|
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
|
||||||
|
end,
|
||||||
|
cwd = "${workspaceFolder}",
|
||||||
|
stopOnEntry = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,12 +58,60 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- NeoVim
|
||||||
|
{ "folke/lazydev.nvim", ft = "lua" },
|
||||||
|
|
||||||
-- Rust
|
-- Rust
|
||||||
{
|
{
|
||||||
"mrcjkb/rustaceanvim",
|
"mrcjkb/rustaceanvim",
|
||||||
version = "^6",
|
version = "^6",
|
||||||
config = function()
|
lazy = false,
|
||||||
vim.g.rusteceanvim = {
|
init = function()
|
||||||
|
vim.g.rustaceanvim = {
|
||||||
|
server = {
|
||||||
|
-- Keymaps in ../../after/ftplugin/rust.lua
|
||||||
|
|
||||||
|
-- LSP configuration
|
||||||
|
default_settings = {
|
||||||
|
["rust-analyzer"] = {
|
||||||
|
cargo = { allFeatures = true },
|
||||||
|
diagnostics = {
|
||||||
|
enable = true,
|
||||||
|
enableExperimental = true,
|
||||||
|
},
|
||||||
|
completion = {
|
||||||
|
addCallArgumentSnippets = true,
|
||||||
|
addCallParenthesis = true,
|
||||||
|
postfix = { enable = true },
|
||||||
|
autoimport = { enable = true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
inlayHints = {
|
||||||
|
bindingModeHints = { enable = false },
|
||||||
|
chainingHints = { enable = true },
|
||||||
|
closingBraceHints = { enable = true, minLines = 25 },
|
||||||
|
closureReturnTypeHints = { enable = "never" },
|
||||||
|
lifetimeElisionHints = { enable = "never", useParameterNames = false },
|
||||||
|
maxLength = 25,
|
||||||
|
parameterHints = { enable = true },
|
||||||
|
reborrowHints = { enable = "never" },
|
||||||
|
renderColons = true,
|
||||||
|
typeHints = {
|
||||||
|
enable = true,
|
||||||
|
hideClosureInitialization = false,
|
||||||
|
hideNamedConstructor = false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
procMacro = {
|
||||||
|
enable = true,
|
||||||
|
ignored = {
|
||||||
|
["async-trait"] = { "async_trait" },
|
||||||
|
["napi-derive"] = { "napi" },
|
||||||
|
["async-recursion"] = { "async_recursion" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
dap = {
|
dap = {
|
||||||
adapter = {
|
adapter = {
|
||||||
type = "executable",
|
type = "executable",
|
||||||
|
|||||||
@@ -5,14 +5,17 @@ return {
|
|||||||
"nvim-neotest/neotest",
|
"nvim-neotest/neotest",
|
||||||
cond = require("config.util").is_not_vscode(),
|
cond = require("config.util").is_not_vscode(),
|
||||||
dependencies = {
|
dependencies = {
|
||||||
|
"nvim-neotest/nvim-nio",
|
||||||
"nvim-lua/plenary.nvim",
|
"nvim-lua/plenary.nvim",
|
||||||
"antoinemadec/FixCursorHold.nvim",
|
"antoinemadec/FixCursorHold.nvim",
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
"marilari88/neotest-vitest",
|
|
||||||
|
"marilari88/neotest-vitest", -- JS/TS/React/Vue
|
||||||
|
"rcasia/neotest-bash", -- bash
|
||||||
},
|
},
|
||||||
opts = {
|
opts = {
|
||||||
-- Do NOT add adapters here
|
-- Do NOT add adapters here
|
||||||
-- Add it to opts.adapters inside config function
|
-- Add it to opts.adapters inside config function below
|
||||||
adapters = {},
|
adapters = {},
|
||||||
status = { virtual_text = true },
|
status = { virtual_text = true },
|
||||||
output = { open_on_run = true },
|
output = { open_on_run = true },
|
||||||
@@ -38,7 +41,6 @@ return {
|
|||||||
},
|
},
|
||||||
}, neotest_ns)
|
}, neotest_ns)
|
||||||
|
|
||||||
-- WARN: Change the following code if we change lazy.nvim
|
|
||||||
if require("lazy.core.config").spec.plugins["trouble.nvim"] ~= nil then
|
if require("lazy.core.config").spec.plugins["trouble.nvim"] ~= nil then
|
||||||
opts.consumers = opts.consumers or {}
|
opts.consumers = opts.consumers or {}
|
||||||
-- Refresh and auto close trouble after running tests
|
-- Refresh and auto close trouble after running tests
|
||||||
@@ -72,6 +74,7 @@ return {
|
|||||||
|
|
||||||
-- TIP: Add adapters here
|
-- TIP: Add adapters here
|
||||||
table.insert(opts.adapters, require("neotest-vitest"))
|
table.insert(opts.adapters, require("neotest-vitest"))
|
||||||
|
table.insert(opts.adapters, require("rustaceanvim.neotest"))
|
||||||
|
|
||||||
if opts.adapters then
|
if opts.adapters then
|
||||||
local adapters = {}
|
local adapters = {}
|
||||||
@@ -107,14 +110,15 @@ return {
|
|||||||
-- r: Run the selected test
|
-- r: Run the selected test
|
||||||
-- a: Attaches to the test result (output)
|
-- a: Attaches to the test result (output)
|
||||||
-- i: Jumps to the code of the test
|
-- i: Jumps to the code of the test
|
||||||
{ "<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Test: Run File" },
|
{ "<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Test: Run All Test in Current File" },
|
||||||
{ "<leader>tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Test: Run All Test Files" },
|
{ "<leader>tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Test: Run All Test Files" },
|
||||||
{ "<leader>tr", function() require("neotest").run.run() end, desc = "Test: Run Nearest" },
|
{ "<leader>tn", function() require("neotest").run.run() end, desc = "Test: Run Nearest" },
|
||||||
{ "<leader>tl", function() require("neotest").run.run_last() end, desc = "Test: Run Last" },
|
{ "<leader>tR", function() require("neotest").run.run_last() end, desc = "Test: Re-Run Last" },
|
||||||
{ "<leader>ts", function() require("neotest").summary.toggle() end, desc = "Test: Toggle Summary" },
|
{ "<leader>ts", function() require("neotest").run.stop() end, desc = "Test: Stop" },
|
||||||
|
|
||||||
{ "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Test: Show Output" },
|
{ "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Test: Show Output" },
|
||||||
{ "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Test: Toggle Output Panel" },
|
{ "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Test: Toggle Output Panel" },
|
||||||
{ "<leader>tS", function() require("neotest").run.stop() end, desc = "Test: Stop" },
|
{ "<leader>tS", function() require("neotest").summary.toggle() end, desc = "Test: Toggle Summary Panel" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ return {
|
|||||||
|
|
||||||
sources = {
|
sources = {
|
||||||
default = {
|
default = {
|
||||||
|
"lazydev",
|
||||||
"lsp",
|
"lsp",
|
||||||
"buffer",
|
"buffer",
|
||||||
"path",
|
"path",
|
||||||
@@ -143,6 +144,11 @@ return {
|
|||||||
return vim.tbl_contains({ "gitcommit", "markdown" }, vim.o.filetype)
|
return vim.tbl_contains({ "gitcommit", "markdown" }, vim.o.filetype)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
lazydev = {
|
||||||
|
name = "LazyDev",
|
||||||
|
module = "lazydev.integrations.blink",
|
||||||
|
score_offset = 1001,
|
||||||
|
},
|
||||||
lsp = {
|
lsp = {
|
||||||
score_offset = 1000,
|
score_offset = 1000,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ return {
|
|||||||
{ "<leader>h", group = "Help", icon = { icon = "", color = "orange" } },
|
{ "<leader>h", group = "Help", icon = { icon = "", color = "orange" } },
|
||||||
{ "<leader>n", group = "Neovim Things", icon = { icon = "", color = "orange" } },
|
{ "<leader>n", group = "Neovim Things", icon = { icon = "", color = "orange" } },
|
||||||
{ "<leader>q", group = "Database", icon = { icon = "", color = "orange" } },
|
{ "<leader>q", group = "Database", icon = { icon = "", color = "orange" } },
|
||||||
|
{ "<leader>r", group = "Rust", icon = { icon = "", color = "orange" } },
|
||||||
{ "<leader>s", group = "Search/Grep", icon = { icon = "", color = "orange" } },
|
{ "<leader>s", group = "Search/Grep", icon = { icon = "", color = "orange" } },
|
||||||
{ "<leader>t", group = "Unit Test" },
|
{ "<leader>t", group = "Unit Test" },
|
||||||
{ "<leader>x", group = "Delete/Disable/Remove", icon = { icon = "", color = "orange" } },
|
{ "<leader>x", group = "Delete/Disable/Remove", icon = { icon = "", color = "orange" } },
|
||||||
|
|||||||
Reference in New Issue
Block a user