Skip to content

Commit 1cedf68

Browse files
committed
Clear children from parent if child session closes
Otherwise the session remains in memory longer than necessary and the sessions widget continues showing the child session until the parent session ends.
1 parent 5b986ed commit 1cedf68

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lua/dap/session.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,16 @@ local function start_debugging(self, request)
10181018
return
10191019
end
10201020

1021+
---@param session Session
10211022
local function on_child_session(session)
10221023
session.parent = self
10231024
self.children[session.id] = session
1025+
session.on_close['dap.session.child'] = function(s)
1026+
if s.parent then
1027+
s.parent.children[s.id] = nil
1028+
s.parent = nil
1029+
end
1030+
end
10241031
session:initialize(config)
10251032
self:response(request, {success = true})
10261033
end

tests/sessions_spec.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ local function run_and_wait_until_initialized(conf, server)
1616
-- wait for initialize and launch requests
1717
return (session and session.initialized and #server.spy.requests == 2)
1818
end)
19-
return dap.session()
19+
return assert(dap.session(), "Must have session after dap.run")
2020
end
2121

2222

@@ -83,5 +83,9 @@ describe('sessions', function()
8383
)
8484
local _, child = next(dap.session().children)
8585
assert.are.same("Subprocess", child.config.name)
86+
87+
srv2.stop()
88+
wait(function() return vim.tbl_count(dap.session().children) == 0 end)
89+
assert.are.same({}, dap.session().children)
8690
end)
8791
end)

0 commit comments

Comments
 (0)