-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathnvim-dap-ui.lua
More file actions
103 lines (99 loc) · 2.81 KB
/
nvim-dap-ui.lua
File metadata and controls
103 lines (99 loc) · 2.81 KB
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
local dap = require("dap")
-- dap.defaults.fallback.terminal_win_cmd = '50vsplit new'
-- dap.defaults.fallback.focus_terminal = true
-- dap.defaults.fallback.external_terminal = {
-- command = '/opt/homebrew/bin/alacritty';
-- args = { '-e' };
-- }
local dapui = require("dapui")
dapui.setup({
icons = { expanded = "", collapsed = "", current_frame = "" },
layouts = {
{
-- You can change the order of elements in the sidebar
elements = {
-- Provide IDs as strings or tables with "id" and "size" keys
{
id = "scopes",
size = 0.25, -- Can be float or integer > 1
},
{ id = "breakpoints", size = 0.25 },
{ id = "stacks", size = 0.25 },
{ id = "watches", size = 0.25 },
},
size = 40,
position = "left",
},
{
elements = {
{ id = "repl", size = 0.3 },
{ id = "console", size = 0.7 },
},
size = 0.25,
position = "bottom",
},
},
})
local M = { dapui_active = false }
local function auto_close(bufnr)
local acid
acid = vim.api.nvim_create_autocmd({ "BufDelete", "BufHidden" }, {
buffer = bufnr,
callback = function()
if M.dapui_active then
require("dapui").close()
M.dapui_active = false
else
dap.repl.close()
end
vim.api.nvim_del_autocmd(acid)
end,
})
end
-- dap.defaults.fallback.terminal_win_cmd = "belowright 12new | set filetype=dap-terminal"
local dapui_console = dap.defaults.fallback.terminal_win_cmd
dap.defaults.fallback.terminal_win_cmd = function()
if M.dapui_active then
local bufnr = dapui_console()
auto_close(bufnr)
return bufnr
else
local cur_win = vim.api.nvim_get_current_win()
-- open terminal
vim.api.nvim_command("belowright 12new")
local bufnr = vim.api.nvim_get_current_buf()
vim.bo[bufnr].modifiable = false
vim.bo[bufnr].swapfile = false
vim.bo[bufnr].buftype = "nofile"
vim.bo[bufnr].filetype = "dap-terminal"
local win = vim.api.nvim_get_current_win()
vim.api.nvim_set_current_win(cur_win)
auto_close(bufnr)
return bufnr, win
end
end
dap.listeners.after.event_initialized["dapui_config"] = function()
-- dapui.open()
if not M.dapui_active then
dap.repl.open()
end
end
-- dap.listeners.before.event_terminated["dapui_config"] = function()
-- dapui.close()
-- end
-- dap.listeners.before.event_exited["dapui_config"] = function()
-- dapui.close()
-- end
-- nvim-dap
vim.api.nvim_create_user_command("DapUIOpen", function()
M.dapui_active = true
require("dapui").open()
end, {})
vim.api.nvim_create_user_command("DapUIClose", function()
M.dapui_active = false
require("dapui").close()
end, {})
vim.api.nvim_create_user_command("DapUIToggle", function()
M.dapui_active = not M.dapui_active
require("dapui").toggle()
end, {})