summary refs log tree commit diff
path: root/.vim/lua/internal/dap.lua
diff options
context:
space:
mode:
Diffstat (limited to '.vim/lua/internal/dap.lua')
-rw-r--r--.vim/lua/internal/dap.lua104
1 files changed, 47 insertions, 57 deletions
diff --git a/.vim/lua/internal/dap.lua b/.vim/lua/internal/dap.lua
index 1790575..4b1d776 100644
--- a/.vim/lua/internal/dap.lua
+++ b/.vim/lua/internal/dap.lua
@@ -2,13 +2,16 @@
 
 local dap = require('dap')
 dap.defaults.fallback.terminal_win_cmd = 'belowright 10new'
-dap.defaults.fallback.terminal_win_cmd = 'belowright 10new'
+dap.defaults.fallback.focus_terminal = false
 
 -- open repl when session starts
 dap.listeners.after['event_initialized']['me'] = function()
-  dap.repl.toggle()
+  -- dap.repl.toggle()
 end
 
+-- try loading dap-launch.json
+-- require('dap.ext.vscode').load_launchjs(vim.fn.getcwd() .. '/dap-launch.json')
+
 -- signs
 vim.fn.sign_define({
   { name = 'DapBreakpoint', text = '🞱', texthl = 'DapBreakpoint', linehl = 'DapBreakpointLn' },
@@ -21,12 +24,12 @@ vim.fn.sign_define({
 vim.keymap.set('n', '<leader>dd', dap.toggle_breakpoint, { desc = 'toggle breakpoint' }) -- convenience
 vim.keymap.set('n', '<leader>db', dap.toggle_breakpoint, { desc = 'toggle breakpoint' })
 vim.keymap.set('n', '<leader>dc', dap.continue, { desc = 'continue' })
-vim.keymap.set('n', '<leader>do', dap.step_over, { desc = 'step over' })
+vim.keymap.set('n', '<leader>ds', dap.step_over, { desc = 'step over' })
 vim.keymap.set('n', '<leader>di', dap.step_into, { desc = 'step into' })
-vim.keymap.set('n', '<leader>dO', dap.step_out, { desc = 'step out' })
+vim.keymap.set('n', '<leader>do', dap.step_out, { desc = 'step out' })
 vim.keymap.set('n', '<leader>dR', dap.repl.toggle, { desc = 'toggle REPL' })
 vim.keymap.set('n', '<leader>dL', dap.run_last, { desc = 'run last' })
-vim.keymap.set('n', '<leader>dt', dap.terminate, { desc = 'terminate' })
+vim.keymap.set('n', '<leader>dq', dap.terminate, { desc = 'terminate' })
 
 local widgets = require('dap.ui.widgets')
 vim.keymap.set('n', '<leader>dh', widgets.hover, { desc = 'hover' })
@@ -39,15 +42,23 @@ vim.keymap.set(
 
 -- Common
 local bin_from_var_or_pick = function()
-  local ok, retval = pcall(vim.api.nvim_buf_get_var, 0, 'dap_bin')
+  local ok, retval = pcall(vim.api.nvim_get_var, 'dap_bin') -- global let g:dap_bin
   if ok then
+    local workspace_folders = vim.lsp.buf.list_workspace_folders()
+    if #workspace_folders >= 1 then
+      retval = retval:gsub(':workspace', workspace_folders[1])
+    end
     return retval
   end
+  -- NOTE: try to resolve binaries from build system
   local bin = nil
-  vim.ui.input({ prompt = 'DAP Binary: ' }, function(choice)
+  vim.ui.input({ prompt = 'DAP: binary to launch: ' }, function(choice)
     bin = choice
   end)
-  return bin
+  if not bin == nil then
+    return bin
+  end
+  return false
 end
 
 -- Go {{{
@@ -106,59 +117,12 @@ dap.configurations.go = {
 -- end of Go }}}
 
 -- C/C++/Rust {{{
--- dap.adapters.cppdbg = {
---   id = 'cppdbg',
---   type = 'executable',
---   command = vim.env.HOME .. '/.local/share/nvim/dap/ms-vscode.cpptools/extension/debugAdapters/bin/OpenDebugAD7',
--- }
 dap.adapters.lldb = {
   type = 'executable',
-  command = vim.trim(vim.fn.system('command -v lldb-vscode')),
+  command = '/usr/bin/lldb-vscode',
   name = 'lldb',
 }
 
--- dap.configurations.c = {
---   {
---     name = 'Launch binary',
---     type = 'cppdbg',
---     request = 'launch',
---     program = function()
---       local file = vim.g.dapbin
---       if file then return file end
---       -- TODO: assuming meson
---       file = vim.trim(vim.fn.system(
---         [[jq -r '..|select(.type?=="executable")|.filename|.[0]' ]] ..
---         vim.lsp.buf.list_workspace_folders()[1] ..
---         [[/build/meson-info/intro-targets.json]]
---       ))
---       local fd = vim.loop.fs_open(file, "r", 438)
---       if file and fd then
---         vim.loop.fs_close(fd)
---         return file
---       end
---       vim.ui.input('binary: ', function(result) file = result end)
---       return file
---     end,
---     cwd = '${workspaceFolder}',
---     stopOnEntry = true,
---   },
---   {
---     name = 'Attach to gdbserver',
---     type = 'cppdbg',
---     request = 'launch',
---     MIMode = 'gdb',
---     miDebuggerServerAddress = 'localhost:1234',
---     miDebuggerPath = '/usr/bin/gdb',
---     cwd = '${workspaceFolder}',
---     program = function()
---       local file = vim.g.dapbin
---       if file then return file end
---       vim.ui.input('binary: ', function(result) file = result end)
---       return file
---     end,
---   },
--- }
-
 dap.configurations.c = {
   {
     name = 'Launch',
@@ -178,6 +142,32 @@ dap.configurations.c = {
   },
 }
 dap.configurations.cpp = dap.configurations.c
-dap.configurations.rust = dap.configurations.c
 
+-- enable rust types
+dap.configurations.rust = vim.tbl_extend('force', dap.configurations.c, {
+  initCommands = function()
+    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)
+
+    return commands
+  end,
+})
 -- end of C/C++/Rust }}}
+
+local dapui = require('dapui')
+dapui.setup {}
+vim.keymap.set('n', '<leader>du', dapui.toggle, { desc = 'toggle ui' })