diff --git a/lua/dapui/components/variables.lua b/lua/dapui/components/variables.lua index af8f90e..9924150 100644 --- a/lua/dapui/components/variables.lua +++ b/lua/dapui/components/variables.lua @@ -103,6 +103,12 @@ function Variables:render(render_state, parent_ref, variables, indent) local child_vars = self.state:variables(variable.variablesReference) if not child_vars then render_state:invalidate() + -- Happens when the parent component is collapsed and the variable + -- reference changes when re-opened. The name is recorded as opened + -- but the variable reference is not yet monitored. + if not self.state:is_monitored(variable.variablesReference) then + self.state:monitor(variable.variablesReference) + end return else self:_get_child_component(variable.name):render( diff --git a/lua/dapui/render/loop.lua b/lua/dapui/render/loop.lua index 2ba4986..0be4a25 100644 --- a/lua/dapui/render/loop.lua +++ b/lua/dapui/render/loop.lua @@ -103,7 +103,6 @@ function M.run(element_names) end end end - else end end end diff --git a/lua/dapui/state.lua b/lua/dapui/state.lua index e8c74bb..8a8f9aa 100644 --- a/lua/dapui/state.lua +++ b/lua/dapui/state.lua @@ -161,6 +161,10 @@ function UIState:monitor(var_ref) end) end +function UIState:is_monitored(var_ref) + return self._monitored_vars[var_ref] ~= nil +end + function UIState:stop_monitor(var_ref) self._monitored_vars[var_ref] = (self._monitored_vars[var_ref] or 1) - 1 if self._monitored_vars[var_ref] then diff --git a/tests/unit/components/variables_spec.lua b/tests/unit/components/variables_spec.lua index a132cb6..6793f2a 100644 --- a/tests/unit/components/variables_spec.lua +++ b/tests/unit/components/variables_spec.lua @@ -16,6 +16,9 @@ describe("checking variables", function() monitor = function(_, ref) monitored[ref] = true end, + is_monitored = function(_, ref) + return monitored[ref] ~= nil + end, stop_monitor = function(_, ref) monitored[ref] = nil end, @@ -182,6 +185,22 @@ describe("checking variables", function() local render_state = render.new_state() local component = Variables(mock_state) + local vars = mock_state:variables(1) + component:render(render_state, 1, vars) + render_state.mappings["expand"][1][1]() + render_state = render.new_state() + mock_state.variables = function() + return nil + end + vars[1].variablesReference = 10 + component:render(render_state, 1, vars) + assert.True(monitored[10]) + end) + + it("monitors child var when variable reference is changed", function() + local render_state = render.new_state() + local component = Variables(mock_state) + local vars = mock_state:variables(1) component:render(render_state, 1, vars) render_state.mappings["expand"][1][1]()