From 1365f782f7785a0122a6c4515fc96675846e82fd Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 30 May 2024 23:19:02 +0200 Subject: [PATCH 1/4] feat!: Drop hydra.nvim and rework DAP --- after/ftplugin/go.lua | 2 - after/ftplugin/python.lua | 2 - lua/core/plugins/dap.lua | 142 ++++++++++++++++++++++++++++++-- lua/core/plugins/dap/dap.lua | 69 ---------------- lua/core/plugins/dap/go.lua | 7 -- lua/core/plugins/dap/python.lua | 7 -- lua/core/plugins/hydra.lua | 9 -- lua/core/plugins/hydra/dap.lua | 47 ----------- 8 files changed, 135 insertions(+), 150 deletions(-) delete mode 100644 lua/core/plugins/dap/dap.lua delete mode 100644 lua/core/plugins/dap/go.lua delete mode 100644 lua/core/plugins/dap/python.lua delete mode 100644 lua/core/plugins/hydra.lua delete mode 100644 lua/core/plugins/hydra/dap.lua diff --git a/after/ftplugin/go.lua b/after/ftplugin/go.lua index 0a26e769..329f3c0c 100644 --- a/after/ftplugin/go.lua +++ b/after/ftplugin/go.lua @@ -2,5 +2,3 @@ local vo = vim.opt_local vo.tabstop = 4 vo.shiftwidth = 4 vo.softtabstop = 4 - -require("core.plugins.dap.dap").setup() diff --git a/after/ftplugin/python.lua b/after/ftplugin/python.lua index 0a26e769..329f3c0c 100644 --- a/after/ftplugin/python.lua +++ b/after/ftplugin/python.lua @@ -2,5 +2,3 @@ local vo = vim.opt_local vo.tabstop = 4 vo.shiftwidth = 4 vo.softtabstop = 4 - -require("core.plugins.dap.dap").setup() diff --git a/lua/core/plugins/dap.lua b/lua/core/plugins/dap.lua index 0f01348a..5510e5b7 100644 --- a/lua/core/plugins/dap.lua +++ b/lua/core/plugins/dap.lua @@ -1,14 +1,142 @@ -local M = { +local user_config = vim.g.config.plugins.dap or {} + +---From https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/go.lua#L145 +---@param config {args?:string[]|fun():string[]?} +local function get_args(config) + local args = type(config.args) == "function" and (config.args() or {}) or config.args or {} + config = vim.deepcopy(config) + ---@cast args string[] + config.args = function() + local new_args = vim.fn.input("Run with args: ", table.concat(args, " ")) --[[@as string]] + return vim.split(vim.fn.expand(new_args) --[[@as string]], " ") + end + return config +end + +-- stylua: ignore +local default_config = { + groups = { + ["d"] = { "Debug" }, + ["dp"] = { "Python" }, + }, + dap = { + keys = { + { "db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" }, + { "dc", function() require("dap").run_to_cursor() end, desc = "Continue" }, + { "di", function() require("dap").step_into() end, desc = "Step Into" }, + { "dn", function() require("dap").step_over() end, desc = "Step Over" }, + { "do", function() require("dap").step_out() end, desc = "Step Out" }, + { "du", function() require("dap").up() end, desc = "Up" }, + { "dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" }, + { "dS", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" }, + { "ds", function() require("dap").continue() end, desc = "Run" }, + { "dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor", }, + { "dl", function() require("dap").run_last() end, desc = "Run Last" }, + { "dt", function() require("dap").terminate() end, desc = "Terminate" }, + { "dK", function() require("dap.ui.widgets").hover() end, desc = "Widgets" }, + }, + }, + dap_ui = { + keys = { + { "du", function() require("dapui").toggle({}) end, desc = "Dap UI" }, + { "dE", function() require("dapui").eval() end, desc = "Eval", mode = { "n", "v" } }, + }, + opts = {}, + }, + dap_virtual_text = { + opts = { + commented = true, + }, + }, + dap_python = { + keys = { + { "dpt", function() require("dap-python").test_method() end, desc = "Debug Method", ft = "python" }, + { "dpc", function() require("dap-python").test_class() end, desc = "Debug Class", ft = "python" }, + { "dps", function() require('dap-python').debug_selection() end, desc = "Debug Selection", ft = "python" } + }, + }, +} + +local config = vim.tbl_deep_extend("force", default_config, user_config) + +return { { "mfussenegger/nvim-dap", lazy = true, + keys = config.dap.keys, dependencies = { - "mfussenegger/nvim-dap-python", - "leoluz/nvim-dap-go", - { "rcarriga/nvim-dap-ui", dependencies = "nvim-neotest/nvim-nio" }, - "theHamsta/nvim-dap-virtual-text", + { + "rcarriga/nvim-dap-ui", + dependencies = "nvim-neotest/nvim-nio", + keys = config.dap_ui.keys, + opts = config.dap_ui.opts, + config = function(_, opts) + local dap, dapui = require("dap"), require("dapui") + dapui.setup(opts) + dap.listeners.after.event_initialized["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 + + local dap_breakpoint = { + error = { + text = "🟥", + texthl = "LspDiagnosticsSignError", + linehl = "", + numhl = "", + }, + rejected = { + text = "", + texthl = "LspDiagnosticsSignHint", + linehl = "", + numhl = "", + }, + stopped = { + text = "⭐️", + texthl = "LspDiagnosticsSignInformation", + linehl = "DiagnosticUnderlineInfo", + numhl = "LspDiagnosticsSignInformation", + }, + } + + vim.fn.sign_define("DapBreakpoint", dap_breakpoint.error) + vim.fn.sign_define("DapStopped", dap_breakpoint.stopped) + vim.fn.sign_define("DapBreakpointRejected", dap_breakpoint.rejected) + end, + }, + { + "theHamsta/nvim-dap-virtual-text", + opts = config.dap_virtual_text.opts, + config = function(_, opts) + require("nvim-dap-virtual-text").setup(opts) + end, + }, + { + "mfussenegger/nvim-dap-python", + keys = config.dap_python.keys, + config = function() + local path = require("mason-registry").get_package("debugpy"):get_install_path() + require("dap-python").setup(path .. "/venv/bin/python") + end, + }, + { + + "leoluz/nvim-dap-go", + config = true, + }, + }, + }, + -- which key integration + { + "folke/which-key.nvim", + optional = true, + opts = { + groups = config.groups, }, }, } - -return M diff --git a/lua/core/plugins/dap/dap.lua b/lua/core/plugins/dap/dap.lua deleted file mode 100644 index b700a729..00000000 --- a/lua/core/plugins/dap/dap.lua +++ /dev/null @@ -1,69 +0,0 @@ -local M = {} - -local function configure() - local dap_breakpoint = { - error = { - text = "🟥", - texthl = "LspDiagnosticsSignError", - linehl = "", - numhl = "", - }, - rejected = { - text = "", - texthl = "LspDiagnosticsSignHint", - linehl = "", - numhl = "", - }, - stopped = { - text = "⭐️", - texthl = "LspDiagnosticsSignInformation", - linehl = "DiagnosticUnderlineInfo", - numhl = "LspDiagnosticsSignInformation", - }, - } - - vim.fn.sign_define("DapBreakpoint", dap_breakpoint.error) - vim.fn.sign_define("DapStopped", dap_breakpoint.stopped) - vim.fn.sign_define("DapBreakpointRejected", dap_breakpoint.rejected) -end - -local function configure_exts() - -- require("dapui").setup() - require("nvim-dap-virtual-text").setup({ - commented = true, - }) - - local dap, dapui = require("dap"), require("dapui") - dapui.setup({}) -- use default - dap.listeners.after.event_initialized["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 -end - -local function configure_debuggers() - require("core.plugins.dap.python").setup() - require("core.plugins.dap.go").setup() -end - -local function create_mapping() - local wk = require("which-key") - wk.register({ - d = { "Debug" }, - }, { prefix = "", mode = "n", {} }) -end - -function M.setup() - configure() -- Configuration - configure_exts() -- Extensions - configure_debuggers() -- Debugger - create_mapping() -- which-key mapping - require("core.plugins.hydra.dap") -- enable Hydra head -end - -return M diff --git a/lua/core/plugins/dap/go.lua b/lua/core/plugins/dap/go.lua deleted file mode 100644 index 6bb33042..00000000 --- a/lua/core/plugins/dap/go.lua +++ /dev/null @@ -1,7 +0,0 @@ -local M = {} - -function M.setup() - require("dap-go").setup() -end - -return M diff --git a/lua/core/plugins/dap/python.lua b/lua/core/plugins/dap/python.lua deleted file mode 100644 index 1365399a..00000000 --- a/lua/core/plugins/dap/python.lua +++ /dev/null @@ -1,7 +0,0 @@ -local M = {} - -function M.setup(_) - require("dap-python").setup("python3", {}) -end - -return M diff --git a/lua/core/plugins/hydra.lua b/lua/core/plugins/hydra.lua deleted file mode 100644 index 232af3cb..00000000 --- a/lua/core/plugins/hydra.lua +++ /dev/null @@ -1,9 +0,0 @@ -local M = { - "anuvyklack/hydra.nvim", - lazy = true, - dependencies = { - "anuvyklack/keymap-layer.nvim", - }, -} - -return M diff --git a/lua/core/plugins/hydra/dap.lua b/lua/core/plugins/hydra/dap.lua deleted file mode 100644 index 9f032797..00000000 --- a/lua/core/plugins/hydra/dap.lua +++ /dev/null @@ -1,47 +0,0 @@ -local Hydra = require("hydra") -local dap = require("dap") - -local hint = [[ - _n_: step over _s_: Continue/Start _b_: Breakpoint - _i_: step into _x_: Disconnect _K_: Hover Variables - _o_: step out _X_: Quit _E_: Evaluate - _c_: to cursor _C_: Close UI _r_: Toggle Repl - ^ - ^ ^ _q_: exit -]] - -local dap_hydra = Hydra({ - hint = hint, - config = { - color = "pink", - invoke_on_body = true, - hint = { - position = "bottom", - border = "rounded", - }, - }, - name = "dap", - mode = { "n", "x" }, - body = "d", - heads = { - { "C", "lua require('dapui').close():DapVirtualTextForceRefresh", { silent = true } }, - { "E", "lua require('dapui').eval()", { silent = true } }, - { "K", "lua require('dap.ui.widgets').hover()", { silent = true } }, - { "X", dap.close, { silent = true } }, - { "b", dap.toggle_breakpoint, { silent = true } }, - { "c", dap.run_to_cursor, { silent = true } }, - { "i", dap.step_into, { silent = true } }, - { "n", dap.step_over, { silent = true } }, - { "o", dap.step_out, { silent = true } }, - { "r", dap.repl.toggle, { silent = true } }, - { "s", dap.continue, { silent = true } }, - { "x", "lua require'dap'.disconnect({ terminateDebuggee = false })", { exit = true, silent = true } }, - { "q", nil, { exit = true, nowait = true } }, - }, -}) - -Hydra.spawn = function(head) - if head == "dap-hydra" then - dap_hydra:activate() - end -end From f40a7275e1a8d834d1e959bc17c73652df894d33 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 30 May 2024 23:19:15 +0200 Subject: [PATCH 2/4] fix: Add "window" which-key --- lua/core/plugins/which-key.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/core/plugins/which-key.lua b/lua/core/plugins/which-key.lua index b3930cce..85c08e9c 100644 --- a/lua/core/plugins/which-key.lua +++ b/lua/core/plugins/which-key.lua @@ -31,6 +31,7 @@ local M = { ["mS"] = { name = "TreeSJ" }, ["s"] = { name = "Search" }, ["t"] = { name = "Toggles" }, + ["w"] = { name = "Window" }, ["z"] = { name = "Spelling" }, }, }, From a51d0f7d6437e18ecec4fc40352cb4ca3c6376be Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 30 May 2024 23:19:31 +0200 Subject: [PATCH 3/4] fix: Use trouble.nvim main branch --- lua/core/plugins/trouble.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/core/plugins/trouble.lua b/lua/core/plugins/trouble.lua index fcc79fa7..c04d1b27 100644 --- a/lua/core/plugins/trouble.lua +++ b/lua/core/plugins/trouble.lua @@ -37,7 +37,6 @@ local config = vim.tbl_deep_extend("force", default_config, user_config) return { { "folke/trouble.nvim", - branch = "dev", event = "VeryLazy", dependencies = { "nvim-tree/nvim-web-devicons" }, enabled = config.enabled, From c95cf736944bf59e39867e5c3cab2e8e22e3fad5 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 30 May 2024 23:19:50 +0200 Subject: [PATCH 4/4] fix: Buffer search and replace mapping --- lua/config/mappings.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config/mappings.lua b/lua/config/mappings.lua index bb054e8f..63e99ac0 100644 --- a/lua/config/mappings.lua +++ b/lua/config/mappings.lua @@ -54,7 +54,7 @@ map("n", "fn", "enew", { desc = "New file" }) map("n", "fs", "w", { desc = "Save file" }) -- search and replace is a pain with a German keyboard layout -map({ "v", "n" }, "sr", ":%s/", { desc = "Buffer search and replace" }) +map({ "n" }, "sr", ":%s/", { desc = "Buffer search and replace" }) -- toggles map("n", "tn", function()