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
|
local dap = require("dap")
local dapui = require("dapui")
local widgets = require('dap.ui.widgets')
local ui = require('dap.ui')
local api = vim.api
local M = {}
local function new_buf()
local buf = api.nvim_create_buf(false, true)
api.nvim_buf_set_option(buf, 'modifiable', false)
api.nvim_buf_set_option(buf, 'buftype', 'nofile')
api.nvim_buf_set_keymap(
buf, "n", "<CR>", "<Cmd>lua require('dap.ui').trigger_actions({ mode = 'first' })<CR>", {})
api.nvim_buf_set_keymap(
buf, "n", "a", "<Cmd>lua require('dap.ui').trigger_actions()<CR>", {})
return buf
end
local scopes = {
refresh_listener = 'scopes',
new_buf = function(view)
local dap = require('dap')
local function reset_tree()
view.tree = nil
end
dap.listeners.after['event_terminated'][view] = reset_tree
dap.listeners.after['event_exited'][view] = reset_tree
local buf = new_buf()
api.nvim_buf_attach(buf, false, {
on_detach = function()
dap.listeners.after['event_terminated'][view] = nil
dap.listeners.after['event_exited'][view] = nil
end
})
return buf
end,
render = function(view)
local session = require('dap').session()
local frame = session and session.current_frame or {}
local tree = view.tree
if not tree then
local spec = vim.deepcopy(require('dap.entity').scope.tree_spec)
spec.extra_context = { view = view }
tree = ui.new_tree(spec)
view.tree = tree
end
local layer = view.layer()
local scopes = frame.scopes or {}
local render
render = function(idx, scope)
if not scope then
return
end
if scope.name ~= 'Locals' then
return
end
tree.render(layer, scope, function()
render(next(scopes, idx))
end)
end
render(next(scopes))
end,
}
M.scopes = function ()
local a = widgets.centered_float(scopes)
-- set cursor at top to make it easier to read
vim.api.nvim_win_set_cursor(a.win, {1, 0})
end
M.fullscopes = function ()
local a = widgets.centered_float(widgets.scopes)
-- set cursor at top to make it easier to read
vim.api.nvim_win_set_cursor(a.win, {1, 0})
end
M.stop = function ()
dap.terminate()
dapui.close()
dap.clear_breakpoints()
end
return M
|