Skip to content

Commit 57f31df

Browse files
committed
fix(watches): reset expanded state when setting var/expr
1 parent adb806e commit 57f31df

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lua/dap-view/watches/actions.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ M.set_watch_expr = function(value, line)
6262
-- Top level expressions are responses for the `evaluate` request, they have no `evaluateName`
6363
-- Therefore, we can always use `setExpression` if the adapter supports it
6464
set.set_expr(expr.name, value)
65+
66+
-- Reset expanded state to avoid leftover lines from the previous expansion
67+
local watched_expr = state.watched_expressions[expr.name]
68+
watched_expr.expanded = false
6569
else
6670
local var = state.variables_by_line[line]
6771

@@ -84,15 +88,19 @@ M.set_watch_expr = function(value, line)
8488
if var.response.evaluateName then
8589
set.set_expr(var.response.evaluateName, value)
8690
else
87-
vim.notify(
91+
return vim.notify(
8892
"Can't set value for " .. var.response.name .. " because it lacks an `evaluateName`"
8993
)
9094
end
9195
elseif hasVariable then
9296
set.set_var(var.response.name, value, var.reference)
9397
else
94-
vim.notify("Adapter lacks support for both `setExpression` and `setVariable` requests")
98+
return vim.notify("Adapter lacks support for both `setExpression` and `setVariable` requests")
9599
end
100+
101+
-- Reset expanded state to avoid leftover lines
102+
local var_state = traversal.find_node(var.response.variablesReference)
103+
var_state.expanded = false
96104
else
97105
vim.notify("No expression or variable under the under cursor")
98106
end
@@ -137,11 +145,11 @@ M.expand_or_collapse = function(line)
137145
if var then
138146
local reference = var.response.variablesReference
139147
if reference > 0 then
140-
local v = traversal.find_node(reference)
141-
if v then
142-
v.expanded = not v.expanded
143-
eval.expand_var(reference, v.children, function(result)
144-
v.children = result
148+
local var_state = traversal.find_node(reference)
149+
if var_state then
150+
var_state.expanded = not var_state.expanded
151+
eval.expand_var(reference, var_state.children, function(result)
152+
var_state.children = result
145153
end)
146154
end
147155
else

0 commit comments

Comments
 (0)