From 581e5d9ca95acb37ca844e721a051e28b015ea62 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 16 Nov 2025 05:42:39 -0600 Subject: [PATCH] feat: add support for rust --- lazy-lock.json | 4 +- lua/plugins/debugging.lua | 534 +++++++++++++++++++------------------- lua/plugins/lsp.lua | 13 + 3 files changed, 289 insertions(+), 262 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index dc11dbd..f7eebbe 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -10,7 +10,7 @@ "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, "github-theme": { "branch": "main", "commit": "c106c9472154d6b2c74b74565616b877ae8ed31d" }, "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" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "155eac5d8609a2f110041f8ac3491664cc126354" }, "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, @@ -28,7 +28,7 @@ "nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" }, "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, "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-lspconfig": { "branch": "master", "commit": "db8fef885009fdec0daeff3e5dda92e1f539611e" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, diff --git a/lua/plugins/debugging.lua b/lua/plugins/debugging.lua index 1bb1dd5..2282dec 100644 --- a/lua/plugins/debugging.lua +++ b/lua/plugins/debugging.lua @@ -1,293 +1,307 @@ return { - "mfussenegger/nvim-dap", - dependencies = { - "rcarriga/nvim-dap-ui", - "nvim-neotest/nvim-nio", - }, - config = function() - local dap = require("dap") - local dapui = require("dapui") + "mfussenegger/nvim-dap", + dependencies = { + "rcarriga/nvim-dap-ui", + "nvim-neotest/nvim-nio", + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") - dapui.setup({ - controls = { - element = "repl", - enabled = true, - icons = { - disconnect = "", - pause = "", - play = "", - run_last = "", - step_back = "", - step_into = "", - step_out = "", - step_over = "", - terminate = "", - }, - }, - element_mappings = {}, - expand_lines = true, - floating = { - border = "rounded", - mappings = { - close = { "q", "" }, - }, - }, - force_buffers = true, - icons = { - collapsed = "", - current_frame = "", - expanded = "", - }, - layouts = { - { - elements = { - { - id = "scopes", - size = 0.25, - }, - { - id = "breakpoints", - size = 0.25, - }, - { - id = "stacks", - size = 0.25, - }, - { - id = "watches", - size = 0.25, - }, - }, - position = "right", - size = 50, - }, - { - elements = { - { - id = "repl", - size = 0.5, - }, - { - id = "console", - size = 0.5, - }, - }, - position = "bottom", - size = 10, - }, - }, - mappings = { - edit = "e", - expand = { "", "<2-LeftMouse>" }, - open = "o", - remove = "d", - repl = "r", - toggle = "t", - }, - render = { - indent = 1, - max_value_lines = 100, - }, - }) + dapui.setup({ + controls = { + element = "repl", + enabled = true, + icons = { + disconnect = "", + pause = "", + play = "", + run_last = "", + step_back = "", + step_into = "", + step_out = "", + step_over = "", + terminate = "", + }, + }, + element_mappings = {}, + expand_lines = true, + floating = { + border = "rounded", + mappings = { + close = { "q", "" }, + }, + }, + force_buffers = true, + icons = { + collapsed = "", + current_frame = "", + expanded = "", + }, + layouts = { + { + elements = { + { + id = "scopes", + size = 0.25, + }, + { + id = "breakpoints", + size = 0.25, + }, + { + id = "stacks", + size = 0.25, + }, + { + id = "watches", + size = 0.25, + }, + }, + position = "right", + size = 50, + }, + { + elements = { + { + id = "repl", + size = 0.5, + }, + { + id = "console", + size = 0.5, + }, + }, + position = "bottom", + size = 10, + }, + }, + mappings = { + edit = "e", + expand = { "", "<2-LeftMouse>" }, + open = "o", + remove = "d", + repl = "r", + toggle = "t", + }, + render = { + indent = 1, + max_value_lines = 100, + }, + }) - for _, adapterType in ipairs({ "node", "chrome", "msedge" }) do - local pwaType = "pwa-" .. adapterType + for _, adapterType in ipairs({ "node", "chrome", "msedge" }) do + local pwaType = "pwa-" .. adapterType - dap.adapters[pwaType] = { - type = "server", - host = "localhost", - port = "${port}", - executable = { - command = "node", - args = { - vim.fn.stdpath("data") .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js", - "${port}", - }, - }, - } + dap.adapters[pwaType] = { + type = "server", + host = "localhost", + port = "${port}", + executable = { + command = "node", + args = { + vim.fn.stdpath("data") .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js", + "${port}", + }, + }, + } - -- this allow us to handle launch.json configurations - -- which specify type as "node" or "chrome" or "msedge" - dap.adapters[adapterType] = function(cb, config) - local nativeAdapter = dap.adapters[pwaType] + -- this allow us to handle launch.json configurations + -- which specify type as "node" or "chrome" or "msedge" + dap.adapters[adapterType] = function(cb, config) + local nativeAdapter = dap.adapters[pwaType] - config.type = pwaType + config.type = pwaType - if type(nativeAdapter) == "function" then - nativeAdapter(cb, config) - else - cb(nativeAdapter) - end - end - end + if type(nativeAdapter) == "function" then + nativeAdapter(cb, config) + else + cb(nativeAdapter) + end + end + end - local enter_launch_url = function() - local co = coroutine.running() - return coroutine.create(function() - vim.ui.input({ prompt = "Enter URL: ", default = "http://localhost:" }, function(url) - if url == nil or url == "" then - return - else - coroutine.resume(co, url) - end - end) - end) - end + local enter_launch_url = function() + local co = coroutine.running() + return coroutine.create(function() + vim.ui.input({ prompt = "Enter URL: ", default = "http://localhost:" }, function(url) + if url == nil or url == "" then + return + else + coroutine.resume(co, url) + end + end) + end) + end - for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact", "vue" }) do - dap.configurations[language] = { - { - type = "pwa-node", - request = "launch", - name = "Launch file using Node.js (nvim-dap)", - program = "${file}", - cwd = "${workspaceFolder}", - }, - { - type = "pwa-node", - request = "attach", - name = "Attach to process using Node.js (nvim-dap)", - processId = require("dap.utils").pick_process, - cwd = "${workspaceFolder}", - }, - -- requires ts-node to be installed globally or locally - { - type = "pwa-node", - request = "launch", - name = "Launch file using Node.js with ts-node/register (nvim-dap)", - program = "${file}", - cwd = "${workspaceFolder}", - runtimeArgs = { "-r", "ts-node/register" }, - }, - { - type = "pwa-chrome", - request = "launch", - name = "Launch Chrome (nvim-dap)", - url = enter_launch_url, - webRoot = "${workspaceFolder}", - sourceMaps = true, - }, - { - type = "pwa-msedge", - request = "launch", - name = "Launch Edge (nvim-dap)", - url = enter_launch_url, - webRoot = "${workspaceFolder}", - sourceMaps = true, - }, - } - end + for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact", "vue" }) do + dap.configurations[language] = { + { + type = "pwa-node", + request = "launch", + name = "Launch file using Node.js (nvim-dap)", + program = "${file}", + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "attach", + name = "Attach to process using Node.js (nvim-dap)", + processId = require("dap.utils").pick_process, + cwd = "${workspaceFolder}", + }, + -- requires ts-node to be installed globally or locally + { + type = "pwa-node", + request = "launch", + name = "Launch file using Node.js with ts-node/register (nvim-dap)", + program = "${file}", + cwd = "${workspaceFolder}", + runtimeArgs = { "-r", "ts-node/register" }, + }, + { + type = "pwa-chrome", + request = "launch", + name = "Launch Chrome (nvim-dap)", + url = enter_launch_url, + webRoot = "${workspaceFolder}", + sourceMaps = true, + }, + { + type = "pwa-msedge", + request = "launch", + name = "Launch Edge (nvim-dap)", + url = enter_launch_url, + webRoot = "${workspaceFolder}", + sourceMaps = true, + }, + } + 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 = { - type = "executable", - command = netcoredbgCommand, - args = { "--interpreter=vscode" }, - } + dap.adapters.coreclr = { + type = "executable", + command = netcoredbgCommand, + args = { "--interpreter=vscode" }, + } - local dotnet_build_project = function() - local default_path = vim.fn.getcwd() .. "/" + local dotnet_build_project = function() + local default_path = vim.fn.getcwd() .. "/" - if vim.g["dotnet_last_proj_path"] ~= nil then - default_path = vim.g["dotnet_last_proj_path"] - end + if vim.g["dotnet_last_proj_path"] ~= nil then + default_path = vim.g["dotnet_last_proj_path"] + 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("Cmd to execute: " .. cmd) + print("") + print("Cmd to execute: " .. cmd) - local f = os.execute(cmd) + local f = os.execute(cmd) - if f == 0 then - print("\nBuild: ✔️ ") - else - print("\nBuild: ❌ (code: " .. f .. ")") - end - end + if f == 0 then + print("\nBuild: ✔️ ") + else + print("\nBuild: ❌ (code: " .. f .. ")") + end + end - local dotnet_get_dll_path = function() - local request = function() - return vim.fn.input("Path to dll to debug: ", vim.fn.getcwd() .. "/bin/Debug/", "file") - end + local dotnet_get_dll_path = function() + local request = function() + return vim.fn.input("Path to dll to debug: ", vim.fn.getcwd() .. "/bin/Debug/", "file") + end - if vim.g["dotnet_last_dll_path"] == nil then - vim.g["dotnet_last_dll_path"] = request() - else - if - vim.fn.confirm("Change the path to dll?\n" .. vim.g["dotnet_last_dll_path"], "&yes\n&no", 2) == 1 - then - vim.g["dotnet_last_dll_path"] = request() - end - end + if vim.g["dotnet_last_dll_path"] == nil then + vim.g["dotnet_last_dll_path"] = request() + else + if + vim.fn.confirm("Change the path to dll?\n" .. vim.g["dotnet_last_dll_path"], "&yes\n&no", 2) == 1 + then + vim.g["dotnet_last_dll_path"] = request() + end + end - return vim.g["dotnet_last_dll_path"] - end + return vim.g["dotnet_last_dll_path"] + end - dap.configurations.cs = { - { - type = "coreclr", - name = "Launch - coreclr (nvim-dap)", - request = "launch", - program = function() - if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then - dotnet_build_project() - end + dap.configurations.cs = { + { + type = "coreclr", + name = "Launch - coreclr (nvim-dap)", + request = "launch", + program = function() + if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then + dotnet_build_project() + end - return dotnet_get_dll_path() - end, - }, - } + return dotnet_get_dll_path() + end, + }, + } - local convertArgStringToArray = function(config) - local c = {} + local codelldb_path = vim.fn.has("win32") + 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 - if k == "args" and type(v) == "string" then - c[k] = require("dap.utils").splitstr(v) - else - c[k] = v - end - end + dap.adapters.lldb = { + type = "server", + port = "${port}", + executable = { + command = codelldb_path, + args = { "--port", "${port}" }, + detached = false, + }, + } - return c - end + local convertArgStringToArray = function(config) + local c = {} - for key, _ in pairs(dap.configurations) do - dap.listeners.on_config[key] = convertArgStringToArray - end + for k, v in pairs(vim.deepcopy(config)) do + if k == "args" and type(v) == "string" then + c[k] = require("dap.utils").splitstr(v) + else + c[k] = v + end + end - dap.listeners.before.attach.dapui_config = function() - dapui.open() - 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 + return c + end - vim.keymap.set("n", "dt", dap.toggle_breakpoint, { desc = "Toggle breakpoint" }) - vim.keymap.set("n", "dbc", dap.clear_breakpoints, { desc = "Clear all breakpoints" }) - vim.keymap.set("n", "dbl", dap.list_breakpoints, { desc = "Clear all breakpoints" }) + for key, _ in pairs(dap.configurations) do + dap.listeners.on_config[key] = convertArgStringToArray + end - 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 + dap.listeners.before.attach.dapui_config = function() + dapui.open() + 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", "dc", continue, { desc = "Continue" }) - end, + vim.keymap.set("n", "dt", dap.toggle_breakpoint, { desc = "Toggle breakpoint" }) + vim.keymap.set("n", "dbc", dap.clear_breakpoints, { desc = "Clear all breakpoints" }) + vim.keymap.set("n", "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", "dc", continue, { desc = "Continue" }) + end, } diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 9a6d4c3..075ab63 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -160,6 +160,19 @@ return { 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", { group = vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev)