Skip to content

Commit

Permalink
Provide feedback if item in variable tree has no children to expand
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed May 30, 2024
1 parent 316f4ed commit 7b18c31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
15 changes: 9 additions & 6 deletions lua/dap/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function variable.has_children(var)
return (var.variables and #var.variables > 0) or var.variablesReference ~= 0
end

---@param var dap.Variable
---@result dap.Variable[]
function variable.get_children(var)
if islist(var.variables) then
return var.variables
Expand All @@ -78,11 +80,12 @@ local function cmp_vars(a, b)
end


---@param var dap.Variable
function variable.fetch_children(var, cb)
local session = require('dap').session()
if var.variables then
cb(variable.get_children(var))
elseif session and var.variablesReference then
elseif session and var.variablesReference > 0 then

---@param err? dap.ErrorResponse
---@param resp? dap.VariableResponse
Expand All @@ -93,11 +96,11 @@ function variable.fetch_children(var, cb)
local variables = resp.variables
local unloaded = #variables
local function countdown()
unloaded = unloaded - 1
if unloaded == 0 then
var.variables = variables
cb(variables)
end
unloaded = unloaded - 1
if unloaded == 0 then
var.variables = variables
cb(variables)
end
end

table.sort(variables, cmp_vars)
Expand Down
2 changes: 1 addition & 1 deletion lua/dap/protocol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
---@field type? string
---@field presentationHint? dap.VariablePresentationHint
---@field evaluateName? string
---@field variablesReference number
---@field variablesReference number if > 0 the variable is structured
---@field namedVariables? number
---@field indexedVariables? number
---@field memoryReference? string
Expand Down
2 changes: 2 additions & 0 deletions lua/dap/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ function M.new_tree(opts)
collapse(layer, value, lnum, context)
elseif opts.has_children(value) then
expand(layer, value, lnum, context)
else
utils.notify("No children on line " .. tostring(lnum) .. ". Can't expand", vim.log.levels.INFO)
end
end,

Expand Down

0 comments on commit 7b18c31

Please sign in to comment.