diff --git a/lua/dap/entity.lua b/lua/dap/entity.lua index 5799d8cc..fe55dce8 100644 --- a/lua/dap/entity.lua +++ b/lua/dap/entity.lua @@ -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 @@ -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 @@ -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) diff --git a/lua/dap/protocol.lua b/lua/dap/protocol.lua index b778ebe5..88b792f8 100644 --- a/lua/dap/protocol.lua +++ b/lua/dap/protocol.lua @@ -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 diff --git a/lua/dap/ui.lua b/lua/dap/ui.lua index b9a700e8..8c074c3d 100644 --- a/lua/dap/ui.lua +++ b/lua/dap/ui.lua @@ -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,