Skip to content
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
10 changes: 8 additions & 2 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ local function launch_external_terminal(terminal, args)
detached = true
}
handle, pid_or_err = uv.spawn(terminal.command, opts, function(code)
handle:close()
if handle then
handle:close()
end
if code ~= 0 then
utils.notify(string.format('Terminal exited %d running %s %s', code, terminal.command, table.concat(full_args, ' ')), vim.log.levels.ERROR)
end
Expand Down Expand Up @@ -641,7 +643,11 @@ function Session:event_stopped(stopped)
end

local should_jump = stopped.reason ~= 'pause' or stopped.allThreadsStopped
if self.stopped_thread_id and should_jump then

-- Some debug adapters allow to continue/step via custom REPL commands (via evaluate)
-- That by-passes `clear_running`, resulting in self.stopped_thread_id still being set
-- Dont auto-continue if`threadId == self.stopped_thread_id`, but stop & jump
if self.stopped_thread_id and self.stopped_thread_id ~= stopped.threadId and should_jump then
if defaults(self).auto_continue_if_many_stopped then
local thread = self.threads[self.stopped_thread_id]
local thread_name = thread and thread.name or self.stopped_thread_id
Expand Down
36 changes: 36 additions & 0 deletions tests/integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,42 @@ describe('dap with fake server', function()
assert.are.same(expected, diagnostics)
end)

it('jumps to location if thread with same id is already stopped', function()
local session = run_and_wait_until_initialized(config, server)

-- Pretend to be stopped
session.stopped_thread_id = 1

server.spy.clear()
server.client.threads = function(self, request)
self:send_response(request, {
threads = { { id = 1, name = 'thread1' }, }
})
end
server.client.stackTrace = function(self, request)
self:send_response(request, {
stackFrames = {
{
id = 1,
name = 'stackFrame1',
line = 1,
},
},
})
end
session:event_stopped({
allThreadsStopped = false,
threadId = 1,
reason = 'breakpoint',
})
vim.wait(1000, function() return #server.spy.requests == 3 end)
local expected_commands = {"threads", "stackTrace", "scopes"}
assert.are.same(
expected_commands,
vim.tbl_map(function(x) return x.command end, server.spy.requests)
)
end)

it('jumps to location on stopped with reason=pause and allThreadsStopped', function()
local session = run_and_wait_until_initialized(config, server)
server.spy.clear()
Expand Down