Skip to content

Commit 7e81998

Browse files
committed
Fix losing session ref when stepping without being stopped
Closes #904
1 parent 5e1e259 commit 7e81998

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lua/dap.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ local function select_config_and_run(opts)
410410
end
411411

412412

413+
--- Get the first stopped session.
414+
--- If no session is stopped, it returns the active session or next in sessions.
413415
---@return Session|nil
414416
local function first_stopped_session()
415417
if session and session.stopped_thread_id then
@@ -420,7 +422,11 @@ local function first_stopped_session()
420422
return s
421423
end
422424
end
423-
return nil
425+
if session then
426+
return session
427+
end
428+
local _, s = next(sessions)
429+
return s
424430
end
425431

426432

tests/integration_spec.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ describe('dap with fake server', function()
356356
local session = run_and_wait_until_initialized(callable_config, server)
357357
assert.are.same(session.config.x, 1)
358358
end)
359+
360+
it("step does nothing if session is not stopped", function()
361+
local session = run_and_wait_until_initialized(config, server)
362+
dap.step_over()
363+
assert.are.same(session, dap.session())
364+
end)
359365
end)
360366

361367
describe('session disconnect', function()

0 commit comments

Comments
 (0)