Skip to content

Commit e94d986

Browse files
authored
fix(dapui): allow certain element to float without active session (#409)
1 parent 055be38 commit e94d986

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

doc/nvim-dap-ui.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ buffer can change over repeated calls
239239
{float_defaults?} `(fun(): dapui.FloatElementArgs)` Default settings for
240240
floating windows. Useful for element windows which should be larger than
241241
their content
242+
{allow_without_session?} `(boolean)` Allows floating the element when
243+
there is no active debug session
242244

243245
*dapui.register_element()*
244246
`register_element`({name}, {element})

lua/dapui/elements/breakpoints.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ return function(client)
1515
--- Mappings:
1616
--- - `open`: Jump to the location the breakpoint is set
1717
--- - `toggle`: Enable/disable the selected breakpoint
18-
dapui.elements.breakpoints = {}
18+
dapui.elements.breakpoints = {
19+
allow_without_session = true,
20+
}
1921

2022
local send_ready = util.create_render_loop(function()
2123
dapui.elements.breakpoints.render()

lua/dapui/elements/watches.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ return function(client)
1919
--- - `remove`: Remove the watched expression.
2020
--- - `edit`: Edit an expression or set the value of a child variable.
2121
--- - `repl`: Send expression to REPL
22-
dapui.elements.watches = {}
22+
dapui.elements.watches = {
23+
allow_without_session = true,
24+
}
25+
2326
local send_ready = util.create_render_loop(function()
2427
dapui.elements.watches.render()
2528
end)

lua/dapui/init.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,16 @@ end
130130
---@param args? dapui.FloatElementArgs
131131
function dapui.float_element(elem_name, args)
132132
nio.run(function()
133-
if not dap.session() then
133+
elem_name = elem_name or query_elem_name()
134+
if not elem_name then
135+
return
136+
end
137+
local elem = elements[elem_name]
138+
if not elem then
139+
util.notify("No such element: " .. elem_name, vim.log.levels.ERROR)
140+
return
141+
end
142+
if not elem.allow_without_session and not dap.session() then
134143
util.notify("No active debug session", vim.log.levels.WARN)
135144
return
136145
end
@@ -140,11 +149,6 @@ function dapui.float_element(elem_name, args)
140149
local line_no = nio.fn.screenrow()
141150
local col_no = nio.fn.screencol()
142151
local position = { line = line_no, col = col_no }
143-
elem_name = elem_name or query_elem_name()
144-
if not elem_name then
145-
return
146-
end
147-
local elem = elements[elem_name]
148152
elem.render()
149153
args = vim.tbl_deep_extend(
150154
"keep",
@@ -402,6 +406,8 @@ dapui.elements = setmetatable({}, {
402406
---@field float_defaults? fun(): dapui.FloatElementArgs Default settings for
403407
--- floating windows. Useful for element windows which should be larger than
404408
--- their content
409+
---@field allow_without_session boolean Allows floating the element when
410+
--- there is no active debug session
405411

406412
--- Registers a new element that can be used within layouts or floating windows
407413
---@param name string Name of the element

0 commit comments

Comments
 (0)