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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
-- Store DAP configuration in a function to load on demand
local function setup_dap()
local dap = require("dap")
local dapview = require("dap-view")
local dapvt = require("nvim-dap-virtual-text")
dapview.setup({})
dapvt.setup {
enabled = true,
enabled_commands = true,
highlight_changed_variables = true,
highlight_new_as_changed = false,
show_stop_reason = true,
commented = false,
only_first_definition = true,
all_references = false,
clear_on_continue = false,
display_callback = function(variable, buf, stackframe, node, options)
if options.virt_text_pos == "inline" then
return " = " .. variable.value:gsub("%s+", " ")
else
return variable.name .. " = " .. variable.value:gsub("%s+", " ")
end
end,
all_frames = true,
virt_lines = true,
virt_text_win_col = nil,
}
-- === PYTHON ===
dap.adapters.python = {
type = "executable",
command = "python",
args = { "-m", "debugpy.adapter" },
}
dap.configurations.python = {
{
type = "python",
request = "launch",
name = "Launch file",
program = "${file}",
console = "integratedTerminal",
justMyCode = true,
},
{
type = "python",
request = "attach",
name = "Attach to process",
connect = { host = "127.0.0.1", port = 5678 },
},
}
-- === RUST ===
dap.adapters.lldb = {
type = "executable",
command = "lldb-dap",
name = "lldb",
}
dap.configurations.rust = {
{
name = "Launch (LLDB)",
type = "lldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = false,
args = {},
runInTerminal = false,
},
{
name = "Attach to process (LLDB)",
type = "lldb",
request = "attach",
pid = require("dap.utils").pick_process,
args = {},
},
}
-- === GO ===
dap.adapters.go = {
type = "executable",
command = "dlv",
args = { "dap" },
}
dap.configurations.go = {
{ type = "go", name = "Debug main.go", request = "launch", program = "${file}" },
{ type = "go", name = "Debug package", request = "launch", program = "${workspaceFolder}" },
{ type = "go", name = "Attach to process", request = "attach", processId = require("dap.utils").pick_process },
}
-- === EVENT LISTENERS ===
dap.listeners.after.event_initialized["dapview_config"] = function() dapview.open() end
dap.listeners.before.event_terminated["dapview_config"] = function() dapview.close() end
dap.listeners.before.event_exited["dapview_config"] = function() dapview.close() end
end
-- Define custom commands to trigger DAP setup
local function define_dap_commands()
vim.api.nvim_create_user_command("DapContinue", function()
setup_dap()
require("dap").continue()
end, {})
vim.api.nvim_create_user_command("DapToggleBreakpoint", function()
setup_dap()
require("dap").toggle_breakpoint()
end, {})
vim.api.nvim_create_user_command("DapStepOver", function()
setup_dap()
require("dap").step_over()
end, {})
vim.api.nvim_create_user_command("DapStepInto", function()
setup_dap()
require("dap").step_into()
end, {})
vim.api.nvim_create_user_command("DapStepOut", function()
setup_dap()
require("dap").step_out()
end, {})
vim.api.nvim_create_user_command("DapTerminate", function()
setup_dap()
require("dap").terminate()
end, {})
end
-- Create autocommand group for DAP
local augroup = vim.api.nvim_create_augroup("DapLazyLoad", { clear = true })
-- Load DAP on filetypes
vim.api.nvim_create_autocmd("FileType", {
group = augroup,
pattern = { "python", "rust", "go" },
callback = function()
define_dap_commands()
end,
})
-- Load DAP on specific commands
vim.api.nvim_create_autocmd("CmdUndefined", {
group = augroup,
pattern = { "DapContinue", "DapToggleBreakpoint", "DapStepOver", "DapStepInto", "DapStepOut", "DapTerminate" },
callback = function()
define_dap_commands()
end,
})
|