feat: add support for rust

This commit is contained in:
Stevan Freeborn
2025-11-16 05:42:39 -06:00
parent 8bb9270e62
commit 581e5d9ca9
3 changed files with 289 additions and 262 deletions
+2 -2
View File
@@ -10,7 +10,7 @@
"friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" },
"github-theme": { "branch": "main", "commit": "c106c9472154d6b2c74b74565616b877ae8ed31d" }, "github-theme": { "branch": "main", "commit": "c106c9472154d6b2c74b74565616b877ae8ed31d" },
"indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" },
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" },
"lualine.nvim": { "branch": "master", "commit": "b8c23159c0161f4b89196f74ee3a6d02cdc3a955" }, "lualine.nvim": { "branch": "master", "commit": "b8c23159c0161f4b89196f74ee3a6d02cdc3a955" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "155eac5d8609a2f110041f8ac3491664cc126354" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "155eac5d8609a2f110041f8ac3491664cc126354" },
"mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" },
@@ -28,7 +28,7 @@
"nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" }, "nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" },
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
"nvim-dap": { "branch": "master", "commit": "7367cec8e8f7a0b1e4566af9a7ef5959d11206a7" }, "nvim-dap": { "branch": "master", "commit": "7367cec8e8f7a0b1e4566af9a7ef5959d11206a7" },
"nvim-dap-python": { "branch": "master", "commit": "bfe572e4458e0ac876b9539a1e9f301c72db8ea0" }, "nvim-dap-python": { "branch": "master", "commit": "64652d1ae1db80870d9aac7132d76e37acd86a26" },
"nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" }, "nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" },
"nvim-lspconfig": { "branch": "master", "commit": "db8fef885009fdec0daeff3e5dda92e1f539611e" }, "nvim-lspconfig": { "branch": "master", "commit": "db8fef885009fdec0daeff3e5dda92e1f539611e" },
"nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
+274 -260
View File
@@ -1,293 +1,307 @@
return { return {
"mfussenegger/nvim-dap", "mfussenegger/nvim-dap",
dependencies = { dependencies = {
"rcarriga/nvim-dap-ui", "rcarriga/nvim-dap-ui",
"nvim-neotest/nvim-nio", "nvim-neotest/nvim-nio",
}, },
config = function() config = function()
local dap = require("dap") local dap = require("dap")
local dapui = require("dapui") local dapui = require("dapui")
dapui.setup({ dapui.setup({
controls = { controls = {
element = "repl", element = "repl",
enabled = true, enabled = true,
icons = { icons = {
disconnect = "", disconnect = "",
pause = "", pause = "",
play = "", play = "",
run_last = "", run_last = "",
step_back = "", step_back = "",
step_into = "", step_into = "",
step_out = "", step_out = "",
step_over = "", step_over = "",
terminate = "", terminate = "",
}, },
}, },
element_mappings = {}, element_mappings = {},
expand_lines = true, expand_lines = true,
floating = { floating = {
border = "rounded", border = "rounded",
mappings = { mappings = {
close = { "q", "<Esc>" }, close = { "q", "<Esc>" },
}, },
}, },
force_buffers = true, force_buffers = true,
icons = { icons = {
collapsed = "", collapsed = "",
current_frame = "", current_frame = "",
expanded = "", expanded = "",
}, },
layouts = { layouts = {
{ {
elements = { elements = {
{ {
id = "scopes", id = "scopes",
size = 0.25, size = 0.25,
}, },
{ {
id = "breakpoints", id = "breakpoints",
size = 0.25, size = 0.25,
}, },
{ {
id = "stacks", id = "stacks",
size = 0.25, size = 0.25,
}, },
{ {
id = "watches", id = "watches",
size = 0.25, size = 0.25,
}, },
}, },
position = "right", position = "right",
size = 50, size = 50,
}, },
{ {
elements = { elements = {
{ {
id = "repl", id = "repl",
size = 0.5, size = 0.5,
}, },
{ {
id = "console", id = "console",
size = 0.5, size = 0.5,
}, },
}, },
position = "bottom", position = "bottom",
size = 10, size = 10,
}, },
}, },
mappings = { mappings = {
edit = "e", edit = "e",
expand = { "<CR>", "<2-LeftMouse>" }, expand = { "<CR>", "<2-LeftMouse>" },
open = "o", open = "o",
remove = "d", remove = "d",
repl = "r", repl = "r",
toggle = "t", toggle = "t",
}, },
render = { render = {
indent = 1, indent = 1,
max_value_lines = 100, max_value_lines = 100,
}, },
}) })
for _, adapterType in ipairs({ "node", "chrome", "msedge" }) do for _, adapterType in ipairs({ "node", "chrome", "msedge" }) do
local pwaType = "pwa-" .. adapterType local pwaType = "pwa-" .. adapterType
dap.adapters[pwaType] = { dap.adapters[pwaType] = {
type = "server", type = "server",
host = "localhost", host = "localhost",
port = "${port}", port = "${port}",
executable = { executable = {
command = "node", command = "node",
args = { args = {
vim.fn.stdpath("data") .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js", vim.fn.stdpath("data") .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js",
"${port}", "${port}",
}, },
}, },
} }
-- this allow us to handle launch.json configurations -- this allow us to handle launch.json configurations
-- which specify type as "node" or "chrome" or "msedge" -- which specify type as "node" or "chrome" or "msedge"
dap.adapters[adapterType] = function(cb, config) dap.adapters[adapterType] = function(cb, config)
local nativeAdapter = dap.adapters[pwaType] local nativeAdapter = dap.adapters[pwaType]
config.type = pwaType config.type = pwaType
if type(nativeAdapter) == "function" then if type(nativeAdapter) == "function" then
nativeAdapter(cb, config) nativeAdapter(cb, config)
else else
cb(nativeAdapter) cb(nativeAdapter)
end end
end end
end end
local enter_launch_url = function() local enter_launch_url = function()
local co = coroutine.running() local co = coroutine.running()
return coroutine.create(function() return coroutine.create(function()
vim.ui.input({ prompt = "Enter URL: ", default = "http://localhost:" }, function(url) vim.ui.input({ prompt = "Enter URL: ", default = "http://localhost:" }, function(url)
if url == nil or url == "" then if url == nil or url == "" then
return return
else else
coroutine.resume(co, url) coroutine.resume(co, url)
end end
end) end)
end) end)
end end
for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact", "vue" }) do for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact", "vue" }) do
dap.configurations[language] = { dap.configurations[language] = {
{ {
type = "pwa-node", type = "pwa-node",
request = "launch", request = "launch",
name = "Launch file using Node.js (nvim-dap)", name = "Launch file using Node.js (nvim-dap)",
program = "${file}", program = "${file}",
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
}, },
{ {
type = "pwa-node", type = "pwa-node",
request = "attach", request = "attach",
name = "Attach to process using Node.js (nvim-dap)", name = "Attach to process using Node.js (nvim-dap)",
processId = require("dap.utils").pick_process, processId = require("dap.utils").pick_process,
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
}, },
-- requires ts-node to be installed globally or locally -- requires ts-node to be installed globally or locally
{ {
type = "pwa-node", type = "pwa-node",
request = "launch", request = "launch",
name = "Launch file using Node.js with ts-node/register (nvim-dap)", name = "Launch file using Node.js with ts-node/register (nvim-dap)",
program = "${file}", program = "${file}",
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
runtimeArgs = { "-r", "ts-node/register" }, runtimeArgs = { "-r", "ts-node/register" },
}, },
{ {
type = "pwa-chrome", type = "pwa-chrome",
request = "launch", request = "launch",
name = "Launch Chrome (nvim-dap)", name = "Launch Chrome (nvim-dap)",
url = enter_launch_url, url = enter_launch_url,
webRoot = "${workspaceFolder}", webRoot = "${workspaceFolder}",
sourceMaps = true, sourceMaps = true,
}, },
{ {
type = "pwa-msedge", type = "pwa-msedge",
request = "launch", request = "launch",
name = "Launch Edge (nvim-dap)", name = "Launch Edge (nvim-dap)",
url = enter_launch_url, url = enter_launch_url,
webRoot = "${workspaceFolder}", webRoot = "${workspaceFolder}",
sourceMaps = true, sourceMaps = true,
}, },
} }
end end
local netcoredbgCommand = vim.fn.stdpath("data") .. "/mason/packages/netcoredbg/netcoredbg/netcoredbg.exe" local netcoredbgCommand = vim.fn.stdpath("data") .. "/mason/packages/netcoredbg/netcoredbg/netcoredbg.exe"
dap.adapters.coreclr = { dap.adapters.coreclr = {
type = "executable", type = "executable",
command = netcoredbgCommand, command = netcoredbgCommand,
args = { "--interpreter=vscode" }, args = { "--interpreter=vscode" },
} }
local dotnet_build_project = function() local dotnet_build_project = function()
local default_path = vim.fn.getcwd() .. "/" local default_path = vim.fn.getcwd() .. "/"
if vim.g["dotnet_last_proj_path"] ~= nil then if vim.g["dotnet_last_proj_path"] ~= nil then
default_path = vim.g["dotnet_last_proj_path"] default_path = vim.g["dotnet_last_proj_path"]
end end
local path = vim.fn.input("Path to your *proj file", default_path, "file") local path = vim.fn.input("Path to your *proj file", default_path, "file")
vim.g["dotnet_last_proj_path"] = path vim.g["dotnet_last_proj_path"] = path
local cmd = "dotnet build -c Debug " .. path .. "" local cmd = "dotnet build -c Debug " .. path .. ""
print("") print("")
print("Cmd to execute: " .. cmd) print("Cmd to execute: " .. cmd)
local f = os.execute(cmd) local f = os.execute(cmd)
if f == 0 then if f == 0 then
print("\nBuild: ✔️ ") print("\nBuild: ✔️ ")
else else
print("\nBuild: ❌ (code: " .. f .. ")") print("\nBuild: ❌ (code: " .. f .. ")")
end end
end end
local dotnet_get_dll_path = function() local dotnet_get_dll_path = function()
local request = function() local request = function()
return vim.fn.input("Path to dll to debug: ", vim.fn.getcwd() .. "/bin/Debug/", "file") return vim.fn.input("Path to dll to debug: ", vim.fn.getcwd() .. "/bin/Debug/", "file")
end end
if vim.g["dotnet_last_dll_path"] == nil then if vim.g["dotnet_last_dll_path"] == nil then
vim.g["dotnet_last_dll_path"] = request() vim.g["dotnet_last_dll_path"] = request()
else else
if if
vim.fn.confirm("Change the path to dll?\n" .. vim.g["dotnet_last_dll_path"], "&yes\n&no", 2) == 1 vim.fn.confirm("Change the path to dll?\n" .. vim.g["dotnet_last_dll_path"], "&yes\n&no", 2) == 1
then then
vim.g["dotnet_last_dll_path"] = request() vim.g["dotnet_last_dll_path"] = request()
end end
end end
return vim.g["dotnet_last_dll_path"] return vim.g["dotnet_last_dll_path"]
end end
dap.configurations.cs = { dap.configurations.cs = {
{ {
type = "coreclr", type = "coreclr",
name = "Launch - coreclr (nvim-dap)", name = "Launch - coreclr (nvim-dap)",
request = "launch", request = "launch",
program = function() program = function()
if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then
dotnet_build_project() dotnet_build_project()
end end
return dotnet_get_dll_path() return dotnet_get_dll_path()
end, end,
}, },
} }
local convertArgStringToArray = function(config) local codelldb_path = vim.fn.has("win32")
local c = {} and vim.fn.stdpath("data") .. "/mason/packages/codelldb/extension/adapter/codelldb.exe"
or vim.fn.stdpath("data") .. "/mason/packages/codelldb/extension/adapter/codelldb"
for k, v in pairs(vim.deepcopy(config)) do dap.adapters.lldb = {
if k == "args" and type(v) == "string" then type = "server",
c[k] = require("dap.utils").splitstr(v) port = "${port}",
else executable = {
c[k] = v command = codelldb_path,
end args = { "--port", "${port}" },
end detached = false,
},
}
return c local convertArgStringToArray = function(config)
end local c = {}
for key, _ in pairs(dap.configurations) do for k, v in pairs(vim.deepcopy(config)) do
dap.listeners.on_config[key] = convertArgStringToArray if k == "args" and type(v) == "string" then
end c[k] = require("dap.utils").splitstr(v)
else
c[k] = v
end
end
dap.listeners.before.attach.dapui_config = function() return c
dapui.open() end
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
vim.keymap.set("n", "<Leader>dt", dap.toggle_breakpoint, { desc = "Toggle breakpoint" }) for key, _ in pairs(dap.configurations) do
vim.keymap.set("n", "<Leader>dbc", dap.clear_breakpoints, { desc = "Clear all breakpoints" }) dap.listeners.on_config[key] = convertArgStringToArray
vim.keymap.set("n", "<Leader>dbl", dap.list_breakpoints, { desc = "Clear all breakpoints" }) end
local continue = function() dap.listeners.before.attach.dapui_config = function()
-- support for vscode launch.json is partial. dapui.open()
-- not all configuration options and features supported end
if vim.fn.filereadable(".vscode/launch.json") then dap.listeners.before.launch.dapui_config = function()
require("dap.ext.vscode").load_launchjs() dapui.open()
end end
dap.continue() dap.listeners.before.event_terminated.dapui_config = function()
end dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
vim.keymap.set("n", "<Leader>dc", continue, { desc = "Continue" }) vim.keymap.set("n", "<Leader>dt", dap.toggle_breakpoint, { desc = "Toggle breakpoint" })
end, vim.keymap.set("n", "<Leader>dbc", dap.clear_breakpoints, { desc = "Clear all breakpoints" })
vim.keymap.set("n", "<Leader>dbl", dap.list_breakpoints, { desc = "Clear all breakpoints" })
local continue = function()
-- support for vscode launch.json is partial.
-- not all configuration options and features supported
if vim.fn.filereadable(".vscode/launch.json") then
require("dap.ext.vscode").load_launchjs()
end
dap.continue()
end
vim.keymap.set("n", "<Leader>dc", continue, { desc = "Continue" })
end,
} }
+13
View File
@@ -160,6 +160,19 @@ return {
vim.lsp.enable("gopls") vim.lsp.enable("gopls")
vim.lsp.config("rust_analyzer", {
settings = {
["rust-analyzer"] = {
diagnostics = {
enable = false,
},
},
},
capabilities = capabilities,
})
vim.lsp.enable("rust_analyzer")
vim.api.nvim_create_autocmd("LspAttach", { vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}), group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev) callback = function(ev)