Skip to content

Commit

Permalink
Merge pull request #86 from Allaman/rework-dap
Browse files Browse the repository at this point in the history
Dap und fixes
  • Loading branch information
Allaman authored May 30, 2024
2 parents a8608d8 + c95cf73 commit 4f630df
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 152 deletions.
2 changes: 0 additions & 2 deletions after/ftplugin/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ local vo = vim.opt_local
vo.tabstop = 4
vo.shiftwidth = 4
vo.softtabstop = 4

require("core.plugins.dap.dap").setup()
2 changes: 0 additions & 2 deletions after/ftplugin/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ local vo = vim.opt_local
vo.tabstop = 4
vo.shiftwidth = 4
vo.softtabstop = 4

require("core.plugins.dap.dap").setup()
2 changes: 1 addition & 1 deletion lua/config/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ map("n", "<leader>fn", "<cmd>enew<cr>", { desc = "New file" })
map("n", "<leader>fs", "<cmd>w<cr>", { desc = "Save file" })

-- search and replace is a pain with a German keyboard layout
map({ "v", "n" }, "<leader>sr", ":%s/", { desc = "Buffer search and replace" })
map({ "n" }, "<leader>sr", ":%s/", { desc = "Buffer search and replace" })

-- toggles
map("n", "<leader>tn", function()
Expand Down
142 changes: 135 additions & 7 deletions lua/core/plugins/dap.lua
Original file line number Diff line number Diff line change
@@ -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 = {
["<leader>d"] = { "Debug" },
["<leader>dp"] = { "Python" },
},
dap = {
keys = {
{ "<leader>db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
{ "<leader>dc", function() require("dap").run_to_cursor() end, desc = "Continue" },
{ "<leader>di", function() require("dap").step_into() end, desc = "Step Into" },
{ "<leader>dn", function() require("dap").step_over() end, desc = "Step Over" },
{ "<leader>do", function() require("dap").step_out() end, desc = "Step Out" },
{ "<leader>du", function() require("dap").up() end, desc = "Up" },
{ "<leader>dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" },
{ "<leader>dS", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" },
{ "<leader>ds", function() require("dap").continue() end, desc = "Run" },
{ "<leader>dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor", },
{ "<leader>dl", function() require("dap").run_last() end, desc = "Run Last" },
{ "<leader>dt", function() require("dap").terminate() end, desc = "Terminate" },
{ "<leader>dK", function() require("dap.ui.widgets").hover() end, desc = "Widgets" },
},
},
dap_ui = {
keys = {
{ "<leader>du", function() require("dapui").toggle({}) end, desc = "Dap UI" },
{ "<leader>dE", function() require("dapui").eval() end, desc = "Eval", mode = { "n", "v" } },
},
opts = {},
},
dap_virtual_text = {
opts = {
commented = true,
},
},
dap_python = {
keys = {
{ "<leader>dpt", function() require("dap-python").test_method() end, desc = "Debug Method", ft = "python" },
{ "<leader>dpc", function() require("dap-python").test_class() end, desc = "Debug Class", ft = "python" },
{ "<leader>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
69 changes: 0 additions & 69 deletions lua/core/plugins/dap/dap.lua

This file was deleted.

7 changes: 0 additions & 7 deletions lua/core/plugins/dap/go.lua

This file was deleted.

7 changes: 0 additions & 7 deletions lua/core/plugins/dap/python.lua

This file was deleted.

9 changes: 0 additions & 9 deletions lua/core/plugins/hydra.lua

This file was deleted.

47 changes: 0 additions & 47 deletions lua/core/plugins/hydra/dap.lua

This file was deleted.

1 change: 0 additions & 1 deletion lua/core/plugins/trouble.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lua/core/plugins/which-key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local M = {
["<leader>mS"] = { name = "TreeSJ" },
["<leader>s"] = { name = "Search" },
["<leader>t"] = { name = "Toggles" },
["<leader>w"] = { name = "Window" },
["<leader>z"] = { name = "Spelling" },
},
},
Expand Down

0 comments on commit 4f630df

Please sign in to comment.