Skip to content

Commit

Permalink
fix(dapui): allow certain element to float without active session (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
w1ck3dg0ph3r authored Dec 27, 2024
1 parent 055be38 commit e94d986
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions doc/nvim-dap-ui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ buffer can change over repeated calls
{float_defaults?} `(fun(): dapui.FloatElementArgs)` Default settings for
floating windows. Useful for element windows which should be larger than
their content
{allow_without_session?} `(boolean)` Allows floating the element when
there is no active debug session

*dapui.register_element()*
`register_element`({name}, {element})
Expand Down
4 changes: 3 additions & 1 deletion lua/dapui/elements/breakpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ return function(client)
--- Mappings:
--- - `open`: Jump to the location the breakpoint is set
--- - `toggle`: Enable/disable the selected breakpoint
dapui.elements.breakpoints = {}
dapui.elements.breakpoints = {
allow_without_session = true,
}

local send_ready = util.create_render_loop(function()
dapui.elements.breakpoints.render()
Expand Down
5 changes: 4 additions & 1 deletion lua/dapui/elements/watches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ return function(client)
--- - `remove`: Remove the watched expression.
--- - `edit`: Edit an expression or set the value of a child variable.
--- - `repl`: Send expression to REPL
dapui.elements.watches = {}
dapui.elements.watches = {
allow_without_session = true,
}

local send_ready = util.create_render_loop(function()
dapui.elements.watches.render()
end)
Expand Down
18 changes: 12 additions & 6 deletions lua/dapui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,16 @@ end
---@param args? dapui.FloatElementArgs
function dapui.float_element(elem_name, args)
nio.run(function()
if not dap.session() then
elem_name = elem_name or query_elem_name()
if not elem_name then
return
end
local elem = elements[elem_name]
if not elem then
util.notify("No such element: " .. elem_name, vim.log.levels.ERROR)
return
end
if not elem.allow_without_session and not dap.session() then
util.notify("No active debug session", vim.log.levels.WARN)
return
end
Expand All @@ -140,11 +149,6 @@ function dapui.float_element(elem_name, args)
local line_no = nio.fn.screenrow()
local col_no = nio.fn.screencol()
local position = { line = line_no, col = col_no }
elem_name = elem_name or query_elem_name()
if not elem_name then
return
end
local elem = elements[elem_name]
elem.render()
args = vim.tbl_deep_extend(
"keep",
Expand Down Expand Up @@ -402,6 +406,8 @@ dapui.elements = setmetatable({}, {
---@field float_defaults? fun(): dapui.FloatElementArgs Default settings for
--- floating windows. Useful for element windows which should be larger than
--- their content
---@field allow_without_session boolean Allows floating the element when
--- there is no active debug session

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

0 comments on commit e94d986

Please sign in to comment.