diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2023-10-26 20:45:44 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2023-10-26 20:45:58 -0500 |
commit | 729448740e31bbdb2e6464a024927fb85b01b4c4 (patch) | |
tree | 5f4d190cca77cc80f7e708935226b428bccb3c87 /nvim | |
parent | 79592b1c2905da30ed04366aff01067e676bb346 (diff) |
fix(nvim): improve DAP config
Diffstat (limited to 'nvim')
-rw-r--r-- | nvim/.config/nvim/lua/plugins/dap.lua | 13 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/dap/adapters.lua | 53 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/dap/configs.lua | 163 |
3 files changed, 113 insertions, 116 deletions
diff --git a/nvim/.config/nvim/lua/plugins/dap.lua b/nvim/.config/nvim/lua/plugins/dap.lua index e5409ef..d0d1135 100644 --- a/nvim/.config/nvim/lua/plugins/dap.lua +++ b/nvim/.config/nvim/lua/plugins/dap.lua @@ -21,7 +21,7 @@ local M = { "theHamsta/nvim-dap-virtual-text", dependencies = { "nvim-treesitter/nvim-treesitter" }, opts = { - commented = true, + virt_text_pos = vim.fn.has("nvim-0.10") == 1 and "inline" or "eol", }, }, }, @@ -30,12 +30,23 @@ local M = { function M:config() require("dap").listeners.after.event_initialized["User"] = function() vim.api.nvim_exec_autocmds("User", { pattern = "DapAttach" }) + + for ns in pairs(vim.diagnostic.get_namespaces()) do + vim.diagnostic.hide(ns) + end + vim.notify("DAP attached", vim.log.levels.INFO) end require("dap").listeners.before.event_terminated["User"] = function() vim.api.nvim_exec_autocmds("User", { pattern = "DapDetach" }) + require("dap").repl.close() + + for ns in pairs(vim.diagnostic.get_namespaces()) do + vim.diagnostic.show(ns) + end + vim.notify("DAP detached", vim.log.levels.INFO) end diff --git a/nvim/.config/nvim/lua/tobyvin/dap/adapters.lua b/nvim/.config/nvim/lua/tobyvin/dap/adapters.lua index 4adb6bd..50ee41d 100644 --- a/nvim/.config/nvim/lua/tobyvin/dap/adapters.lua +++ b/nvim/.config/nvim/lua/tobyvin/dap/adapters.lua @@ -1,30 +1,31 @@ -local M = {} +local M = { + nlua = function(callback, config) + callback({ type = "server", host = config.host, port = config.port }) + end, + lldb = { + type = "executable", + command = "/usr/bin/lldb-vscode", + name = "lldb", + }, + gdb = { + type = "executable", + command = "gdb", + args = { "-i", "dap" }, + }, + codelldb = function(on_config, _) + local codelldb_path = vim.fn.exepath("codelldb") + local liblldb_path = vim.fn.resolve(codelldb_path):gsub("/codelldb$", "/extension/lldb/lib/liblldb.so") -M.nlua = function(callback, config) - callback({ type = "server", host = config.host, port = config.port }) -end - -M.lldb = { - type = "executable", - command = "/usr/bin/lldb-vscode", - name = "lldb", + on_config({ + type = "server", + port = "${port}", + host = "127.0.0.1", + executable = { + command = codelldb_path, + args = { "--liblldb", liblldb_path, "--port", "${port}" }, + }, + }) + end, } -M.codelldb = function(on_config, _) - local codelldb_path = vim.fn.exepath("codelldb") - local liblldb_path = vim.fn.resolve(codelldb_path):gsub("/codelldb$", "/extension/lldb/lib/liblldb.so") - - on_config({ - type = "server", - port = "${port}", - host = "127.0.0.1", - executable = { - command = codelldb_path, - args = { "--liblldb", liblldb_path, "--port", "${port}" }, - }, - }) -end - -M.rt_lldb = M.codelldb - return M diff --git a/nvim/.config/nvim/lua/tobyvin/dap/configs.lua b/nvim/.config/nvim/lua/tobyvin/dap/configs.lua index 4b5d7b9..e9b7c50 100644 --- a/nvim/.config/nvim/lua/tobyvin/dap/configs.lua +++ b/nvim/.config/nvim/lua/tobyvin/dap/configs.lua @@ -1,95 +1,80 @@ -local Job = require("plenary").job -local M = {} - -local select_executable = function(cwd) - cwd = vim.fn.expand(vim.F.if_nil(cwd, vim.fn.getcwd())) - - local finders = { - fd = { "--type", "x", "--hidden" }, - fdfind = { "--type", "x", "--hidden" }, - find = { ".", "-type", "f", "--executable" }, - } - - local command, args - for finder, finder_args in pairs(finders) do - if vim.fn.executable(finder) == 1 then - command = finder - args = finder_args - end - end - - if command == nil then - vim.notify("Failed to locate finder tool", vim.log.levels.ERROR, { title = "[dap.configs] select_executable" }) - return - end - - local items = Job:new({ - command = command, - args = args, - cwd = cwd, - enable_recording = true, - }):sync() - - local result - vim.ui.select(items, { kind = "executables" }, function(input) - result = input - end) - return result -end - -M.lua = { - name = "Attach to running Neovim instance", - type = "nlua", - request = "attach", - host = function() - local host - vim.ui.input({ prompt = "Host: ", default = "127.0.0.1" }, function(input) - host = input - end) - return host - end, - port = function() - local host - vim.ui.input({ prompt = "Port: ", default = "7777" }, function(input) - host = input - end) - return host - end, -} - -M.c = { - { - name = "Launch c file", - type = "codelldb", - request = "launch", - program = select_executable, - cwd = "${workspaceFolder}", - stopOnEntry = false, - runInTerminal = false, +local M = { + lua = { + name = "Attach to running Neovim instance", + type = "nlua", + request = "attach", + host = function() + local host + vim.ui.input({ prompt = "Host: ", default = "127.0.0.1" }, function(input) + host = input + end) + return host + end, + port = function() + local host + vim.ui.input({ prompt = "Port: ", default = "7777" }, function(input) + host = input + end) + return host + end, }, -} - -M.cpp = { - { - name = "Launch c++ file", - type = "codelldb", - request = "launch", - program = select_executable, - cwd = "${workspaceFolder}", - stopOnEntry = false, - runInTerminal = false, + c = { + { + name = "Launch", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + runInTerminal = false, + }, }, -} + cpp = { + { + name = "Launch", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + runInTerminal = false, + }, + }, + rust = { + { + name = "Launch", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + runInTerminal = false, + initCommands = function() + -- Find out where to look for the pretty printer Python module + local rustc_sysroot = vim.fn.trim(vim.fn.system("rustc --print sysroot")) + + local script_import = 'command script import "' .. rustc_sysroot .. '/lib/rustlib/etc/lldb_lookup.py"' + local commands_file = rustc_sysroot .. "/lib/rustlib/etc/lldb_commands" + + local commands = {} + local file = io.open(commands_file, "r") + if file then + for line in file:lines() do + table.insert(commands, line) + end + file:close() + end + table.insert(commands, 1, script_import) -M.rust = { - { - name = "Launch rust file", - type = "codelldb", - request = "launch", - program = select_executable, - cwd = "${workspaceFolder}", - stopOnEntry = false, - runInTerminal = false, + return commands + end, + }, }, } |