Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide feedback if item in variable tree has no children to expand #1234

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading