diff options
Diffstat (limited to 'nvim/.config/nvim/lua/tobyvin/dap/configs.lua')
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/dap/configs.lua | 163 |
1 files changed, 74 insertions, 89 deletions
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, + }, }, } |