Skip to content

Commit

Permalink
Restore stopped state if goto errors
Browse files Browse the repository at this point in the history
Problem:

A debug adapter can respond to goto with an error - e.g. if attempting
to jump to a location where there is no code to execute.

If that happened, selecting another goto location was no longer possible
because the stopped state had been cleared.

Solution:

Restore stopped state if goto fails
  • Loading branch information
mfussenegger committed Sep 12, 2024
1 parent 20a4859 commit 90616ae
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,18 @@ function Session:_request_scopes(current_frame)
end


---@param session dap.Session
local function clear_running(session, thread_id)
vim.fn.sign_unplace(session.sign_group)
thread_id = thread_id or session.stopped_thread_id
session.stopped_thread_id = nil
local thread = session.threads[thread_id]
if thread then
thread.stopped = false
end
end


--- Goto specified line (source and col are optional)
function Session:_goto(line, source, col)
local frame = self.current_frame
Expand Down Expand Up @@ -845,14 +857,16 @@ function Session:_goto(line, source, col)
if not target then
return
end
local params = {threadId = self.stopped_thread_id, targetId = target.id }
local thread = self.threads[self.stopped_thread_id]
if thread then
thread.stopped = false
end
self.stopped_thread_id = nil
local stopped_thread_id = self.stopped_thread_id
local params = {threadId = stopped_thread_id, targetId = target.id }
local thread = self.threads[stopped_thread_id]
clear_running(self, stopped_thread_id)
local goto_err = self:request('goto', params)
if goto_err then
self.stopped_thread_id = stopped_thread_id
if thread then
thread.stopped = true
end
utils.notify('Error executing goto: ' .. utils.fmt_error(goto_err), vim.log.levels.ERROR)
end
end)()
Expand Down Expand Up @@ -1550,18 +1564,6 @@ function Session:_pause(thread_id, cb)
end


---@param session dap.Session
local function clear_running(session, thread_id)
vim.fn.sign_unplace(session.sign_group)
thread_id = thread_id or session.stopped_thread_id
session.stopped_thread_id = nil
local thread = session.threads[thread_id]
if thread then
thread.stopped = false
end
end


function Session:restart_frame()
if not self.capabilities.supportsRestartFrame then
utils.notify('Debug Adapter does not support restart frame', vim.log.levels.INFO)
Expand Down

0 comments on commit 90616ae

Please sign in to comment.