aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha/dap.lua
blob: 6215f954eef0606db1462b9e71960697e851b529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
local dap, dapui, dap_install, dap_go = require("dap"), require("dapui"), require("dap-install"), require("dap-go")

require("nvim-dap-virtual-text").setup()

dapui.setup({
	icons = { expanded = "▾", collapsed = "▸" },
	layouts = {
		{
			elements = {
				"scopes",
				"breakpoints",
				"stacks",
				"watches",
			},
			size = 80,
			position = "left",
		},
		{
			elements = {
				"repl",
				-- 'console',
			},
			size = 10,
			position = "bottom",
		},
	},
})

dap_go.setup()

vim.fn.sign_define("DapBreakpoint", { text = "ß", texthl = "", linehl = "", numhl = "" })

dap_install.config("php", {
	configurations = {
		{
			type = "php",
			request = "launch",
			name = "Listen for Xdebug",
			port = 9003,
			pathMappings = function()
				local sail = vim.call("composer#query", "require-dev.laravel/sail")
				if sail == "" then
					return { ["/app"] = vim.fn.getcwd() }
				end
				return { ["/var/www/html"] = vim.fn.getcwd() }
			end,
		},
	},
})

-- Events Listeners
dap.listeners.after.event_initialized["dapui_config"] = function()
	dapui.open({})
end

local hydra = require("hydra")
local hint = [[
 Nvim DAP
 _d_: Start/Continue  _j_: StepOver _k_: StepOut _l_: StepInto ^
 _bp_: Toogle Breakpoint  _cb_: Conditional Breakpoint ^
 _c_: Run To Cursor  _tt_: Go Debug Test
 _sp_: Stop Debbuging
 ^^                                                      _<Esc>_
]]
hydra({
	name = "dap",
	hint = hint,
	mode = "n",
	config = {
		color = "amaranth",
		invoke_on_body = true,
		hint = {
			border = "rounded",
			position = "bottom",
		},
	},
	body = "<leader>d",
	heads = {
		{ "d", dap.continue },
		{ "bp", dap.toggle_breakpoint },
		{ "l", dap.step_into },
		{ "j", dap.step_over },
		{ "k", dap.step_out },
		{ "c", dap.run_to_cursor },
		{ "tt", dap_go.debug_test },
		{
			"cb",
			function()
				vim.ui.input({ prompt = "Condition: " }, function(condition)
					dap.toggle_breakpoint(condition)
				end)
			end,
		},

		{
			"sp",
			function()
				dap.terminate()
				dapui.close({})
				dap.clear_breakpoints()
			end,
		},

		{ "<Esc>", nil, { exit = true } },
	},
})