From cc9a8d71f1ec24a9b307612d4d64ab4d981285d9 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Fri, 29 Mar 2024 14:00:15 -0400 Subject: [PATCH] [wip] nvim: start migration to nvim-dap --- .gitmodules | 12 ++ src/.config/nvim/coding.vim | 2 +- src/.config/nvim/lua/coding.lua | 4 +- src/.config/nvim/lua/confutil.lua | 4 +- src/.config/nvim/lua/debugging.lua | 138 ++++++++++++++++++ src/.config/nvim/lua/init.lua | 1 + .../share/nvim/site/pack/3pp/start/nvim-dap | 1 + .../nvim/site/pack/3pp/start/nvim-dap-ui | 1 + .../share/nvim/site/pack/3pp/start/nvim-nio | 1 + 9 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 src/.config/nvim/lua/debugging.lua create mode 160000 src/.local/share/nvim/site/pack/3pp/start/nvim-dap create mode 160000 src/.local/share/nvim/site/pack/3pp/start/nvim-dap-ui create mode 160000 src/.local/share/nvim/site/pack/3pp/start/nvim-nio diff --git a/.gitmodules b/.gitmodules index 48cd873..2744360 100644 --- a/.gitmodules +++ b/.gitmodules @@ -99,3 +99,15 @@ [submodule "src/.local/share/nvim/site/pack/3pp/start/colorbuddy.nvim"] path = src/.local/share/nvim/site/pack/3pp/start/colorbuddy.nvim url = https://github.com/tjdevries/colorbuddy.nvim.git +[submodule "nvim-dap"] + path = nvim-dap + url = https://github.com/mfussenegger/nvim-dap.git +[submodule "src/.local/share/nvim/site/pack/3pp/start/nvim-dap"] + path = src/.local/share/nvim/site/pack/3pp/start/nvim-dap + url = https://github.com/mfussenegger/nvim-dap.git +[submodule "src/.local/share/nvim/site/pack/3pp/start/nvim-dap-ui"] + path = src/.local/share/nvim/site/pack/3pp/start/nvim-dap-ui + url = https://github.com/rcarriga/nvim-dap-ui.git +[submodule "src/.local/share/nvim/site/pack/3pp/start/nvim-nio"] + path = src/.local/share/nvim/site/pack/3pp/start/nvim-nio + url = https://github.com/nvim-neotest/nvim-nio diff --git a/src/.config/nvim/coding.vim b/src/.config/nvim/coding.vim index 0b43f88..f209bdb 100644 --- a/src/.config/nvim/coding.vim +++ b/src/.config/nvim/coding.vim @@ -7,7 +7,7 @@ set foldexpr=nvim_treesitter#foldexpr() " unfold by default set foldlevel=99 -source $XDG_CONFIG_HOME/nvim/vimspector.vim +" source $XDG_CONFIG_HOME/nvim/vimspector.vim " auto-pairs let g:AutoPairsFlyMode = 0 diff --git a/src/.config/nvim/lua/coding.lua b/src/.config/nvim/lua/coding.lua index 98562e7..d4a3efc 100644 --- a/src/.config/nvim/lua/coding.lua +++ b/src/.config/nvim/lua/coding.lua @@ -1,7 +1,7 @@ -- stuff for coding -confutil = require("confutil") -keymap = confutil.keymap +local confutil = require("confutil") +local keymap = confutil.keymap ------ diff --git a/src/.config/nvim/lua/confutil.lua b/src/.config/nvim/lua/confutil.lua index 552c587..1fb1402 100644 --- a/src/.config/nvim/lua/confutil.lua +++ b/src/.config/nvim/lua/confutil.lua @@ -10,7 +10,7 @@ function M.keymap(key, cmd, params) default_params = { silent=true, - mode="n", + mode={'n'}, noremap=true, } setmetatable(params, { @@ -19,7 +19,7 @@ function M.keymap(key, cmd, params) end }) - vim.api.nvim_set_keymap(params.mode, key, cmd, { silent=params.silent, noremap=params.noremap }) + vim.keymap.set(params.mode, key, cmd, { silent=params.silent, noremap=params.noremap }) end -- see ~/.config/dot_profile.example for info diff --git a/src/.config/nvim/lua/debugging.lua b/src/.config/nvim/lua/debugging.lua new file mode 100644 index 0000000..6111699 --- /dev/null +++ b/src/.config/nvim/lua/debugging.lua @@ -0,0 +1,138 @@ +-- dap and debugging related configurations + +local confutil = require("confutil") +local keymap = confutil.keymap + +local dap = require("dap") +local dapui = require("dapui") + +-------------------------------- +-------------------------------- +-- dap-ui configuration +-------------------------------- +-------------------------------- + +---------------- +-- key bindings +---------------- + +keymap("dd", dapui.setup) +keymap("rs", dap.continue) +keymap("rt", dap.restart) +keymap("rr", dap.terminate) +keymap("", dap.step_into) +keymap("", dap.step_over) +keymap("", dap.step_out) +keymap("dsf", dap.toggle_breakpoint) +keymap("dsc", dap.clear_breakpoints) +keymap("dsF", function() + dap.set_breakpoint(vim.fn.input("cond: ")) +end) +keymap("K", dapui.eval, {mode = {'n', 'v'}}) + +---------------- +-- ui setup +---------------- + +-- https://github.com/rcarriga/nvim-dap-ui/blob/master/doc/nvim-dap-ui.txt +dapui.setup({ + controls = { + enabled = false, + }, + icons = { + collapsed = ">", + current_frame = ">", + expanded = "v", + }, + layouts = { + { + elements = { + { + id = "stacks", + size = 0.20 + }, + { + id = "scopes", + size = 0.40 + }, + { + id = "watches", + size = 0.40 + }, + }, + position = "left", + size = 40 + }, + { + elements = { + { + id = "repl", + size = 1 + }, + }, + position = "bottom", + size = 10 + }, + { + elements = { + { + id = "console", + size = 1 + } + }, + position = "right", + size = 50 + }, + }, +}) + +dap.listeners.after.launch.dapui_config = function() + dapui.open() +end +dap.listeners.after.attach.dapui_config = function() + dapui.open() +end +dap.listeners.after.event_terminated.dapui_config = function() + dapui.close() +end +dap.listeners.after.event_exited.dapui_config = function() + dapui.close() +end + + +-------------------------------- +-------------------------------- +-- debug adapter configs +-------------------------------- +-------------------------------- + +-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#python +dap.adapters.python = function(cb, config) + if config.request == 'attach' then + assert(false, "attach not implemented") + else + cb({ + type = 'executable', + command = "python", + args = { "-m", "debugpy.adapter" }, + options = { + source_filetype = "python", + } + }) + end +end + +dap.configurations.python = { + { + -- dap parts + type = "python"; + request = "launch"; + name = "launch file"; + + -- debugger parts + program = "${file}"; + -- this could be smarter (e.g., try to find a virtual env) + pythonPath = function() return "/usr/bin/python" end; + console = "integratedTerminal"; + } +} diff --git a/src/.config/nvim/lua/init.lua b/src/.config/nvim/lua/init.lua index 776034c..966695b 100644 --- a/src/.config/nvim/lua/init.lua +++ b/src/.config/nvim/lua/init.lua @@ -101,4 +101,5 @@ end if dotprofile >= profile_table.DEFAULT then require("coding") + require("debugging") end diff --git a/src/.local/share/nvim/site/pack/3pp/start/nvim-dap b/src/.local/share/nvim/site/pack/3pp/start/nvim-dap new file mode 160000 index 0000000..405df1d --- /dev/null +++ b/src/.local/share/nvim/site/pack/3pp/start/nvim-dap @@ -0,0 +1 @@ +Subproject commit 405df1dcc2e395ab5173a9c3d00e03942c023074 diff --git a/src/.local/share/nvim/site/pack/3pp/start/nvim-dap-ui b/src/.local/share/nvim/site/pack/3pp/start/nvim-dap-ui new file mode 160000 index 0000000..edfa93f --- /dev/null +++ b/src/.local/share/nvim/site/pack/3pp/start/nvim-dap-ui @@ -0,0 +1 @@ +Subproject commit edfa93f60b189e5952c016eee262d0685d838450 diff --git a/src/.local/share/nvim/site/pack/3pp/start/nvim-nio b/src/.local/share/nvim/site/pack/3pp/start/nvim-nio new file mode 160000 index 0000000..33c62b3 --- /dev/null +++ b/src/.local/share/nvim/site/pack/3pp/start/nvim-nio @@ -0,0 +1 @@ +Subproject commit 33c62b3eadd8154169e42144de16ba4db6784bec