-
Notifications
You must be signed in to change notification settings - Fork 0
/
dap.lua
133 lines (117 loc) · 4.95 KB
/
dap.lua
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
local u = require("functions.utils")
local adapters = require("plugins.dap.adapters")
local configurations = require("plugins.dap.configs")
local mason = require("mason")
local mason_dap = require("mason-nvim-dap")
local dap = require("dap")
local ui = require("dapui")
dap.set_log_level("TRACE")
-- ╭──────────────────────────────────────────────────────────╮
-- │ Debuggers │
-- ╰──────────────────────────────────────────────────────────╯
-- We need the actual programs to connect to running instances of our code.
-- Debuggers are installed via https://github.com/jayp0521/mason-nvim-dap.nvim
-- The VSCode debugger requires a special adapter, seen in /lua/plugins/dap/adapters.lua
mason.setup()
mason_dap.setup({
automatic_installation = true
})
-- ╭──────────────────────────────────────────────────────────╮
-- │ Adapters │
-- ╰──────────────────────────────────────────────────────────╯
-- Neovim needs a debug adapter with which it can communicate. Neovim can either
-- launch the debug adapter itself, or it can attach to an existing one.
-- To tell Neovim if it should launch a debug adapter or connect to one, and if
-- so, how, you need to configure them via the `dap.adapters` table.
adapters.setup(dap)
-- ╭──────────────────────────────────────────────────────────╮
-- │ Configuration │
-- ╰──────────────────────────────────────────────────────────╯
-- In addition to launching (possibly) and connecting to a debug adapter, Neovim
-- needs to instruct the adapter itself how to launch and connect to the program
-- that you are trying to debug (the debugee).
configurations.setup(dap)
-- ╭──────────────────────────────────────────────────────────╮
-- │ Keybindings + UI │
-- ╰──────────────────────────────────────────────────────────╯
vim.fn.sign_define('DapBreakpoint', { text = '🐞' })
local function dap_start_debugging()
dap.continue({})
vim.cmd("tabedit %")
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-o>", false, true, true), "n", false)
ui.toggle({})
end
vim.keymap.set("n", "<leader>ds", dap_start_debugging)
vim.keymap.set("n", "<leader>dl", require("dap.ui.widgets").hover)
vim.keymap.set("n", "<leader>dc", dap.continue)
vim.keymap.set("n", "<leader>db", dap.toggle_breakpoint)
vim.keymap.set("n", "<leader>dn", dap.step_over)
vim.keymap.set("n", "<leader>di", dap.step_into)
vim.keymap.set("n", "<leader>do", dap.step_out)
local function dap_clear_breakpoints()
dap.clear_breakpoints()
require("notify")("Breakpoints cleared", "warn")
end
vim.keymap.set("n", "<leader>dC", dap_clear_breakpoints)
-- TODO: How to get current adapter config? Could restart with current arguments
local function dap_restart_current_session()
dap.terminate()
vim.defer_fn(
function()
dap.continue()
end,
300)
end
vim.keymap.set("n", "<leader>dr", dap_restart_current_session)
local function dap_end_debug()
dap.clear_breakpoints()
ui.toggle({})
dap.terminate({}, { terminateDebuggee = true }, function()
vim.cmd.bd()
u.resize_vertical_splits()
require("notify")("Debugger session ended", "warn")
end)
end
vim.keymap.set("n", "<leader>de", dap_end_debug)
-- UI Settings
ui.setup({
icons = { expanded = "▾", collapsed = "▸" },
mappings = {
expand = { "<CR>", "<2-LeftMouse>" },
open = "o",
remove = "d",
edit = "e",
repl = "r",
toggle = "t",
},
layouts = {
{
elements = {
"scopes",
},
size = 0.3,
position = "right"
},
{
elements = {
"repl",
"breakpoints"
},
size = 0.3,
position = "bottom",
},
},
floating = {
-- max_height = nil,
-- max_width = nil,
border = "single",
mappings = {
close = { "q", "<Esc>" },
},
},
windows = { indent = 1 },
render = {
max_type_length = nil,
},
})