Skip to content

Commit 413b993

Browse files
committed
fix(threads)!: don't show stack if no thread is stopped
1 parent 02be707 commit 413b993

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

lua/dap-view/events.lua

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ dap.listeners.after.scopes[SUBSCRIPTION_ID] = function(session)
8787
if util.is_buf_valid(state.bufnr) then
8888
if state.current_section == "scopes" then
8989
scopes.refresh()
90-
end
91-
if state.current_section == "sessions" then
90+
elseif state.current_section == "sessions" then
9291
sessions.refresh()
9392
end
9493
end
@@ -107,6 +106,20 @@ dap.listeners.after.scopes[SUBSCRIPTION_ID] = function(session)
107106
end
108107
end
109108

109+
---@type dap.RequestListener[]
110+
local continue = { "event_continued", "continue" }
111+
112+
for _, listener in ipairs(continue) do
113+
dap.listeners.after[listener][SUBSCRIPTION_ID] = function()
114+
-- Program is no longer stopped, refresh threads to prevent user from jumping to a no longer accurate location
115+
if state.current_section == "threads" then
116+
require("dap-view.views").switch_to_view("threads")
117+
end
118+
119+
winbar.redraw_controls()
120+
end
121+
end
122+
110123
dap.listeners.after.variables[SUBSCRIPTION_ID] = function()
111124
if state.current_section == "watches" then
112125
require("dap-view.views").switch_to_view("watches")
@@ -178,27 +191,28 @@ dap.listeners.after.event_terminated[SUBSCRIPTION_ID] = function()
178191
winbar.redraw_controls()
179192
end
180193

181-
--- Refresh winbar on dap session state change events not having a dedicated event handler
182-
local winbar_redraw_events = { "continue", "disconnect", "event_exited", "event_stopped", "restart" }
194+
---@type dap.RequestListener[]
195+
local winbar_redraw = { "disconnect", "event_exited", "event_stopped", "restart" }
183196

184-
for _, event in ipairs(winbar_redraw_events) do
185-
dap.listeners.after[event][SUBSCRIPTION_ID] = winbar.redraw_controls
197+
for _, listener in ipairs(winbar_redraw) do
198+
dap.listeners.after[listener][SUBSCRIPTION_ID] = winbar.redraw_controls
186199
end
187200

188-
local auto_open_events = { "attach", "launch" }
201+
---@type dap.RequestListener[]
202+
local auto_open = { "attach", "launch" }
189203

190-
for _, event in ipairs(auto_open_events) do
191-
dap.listeners.before[event][SUBSCRIPTION_ID] = function()
204+
for _, listener in ipairs(auto_open) do
205+
dap.listeners.before[listener][SUBSCRIPTION_ID] = function()
192206
if setup.config.auto_toggle then
193207
require("dap-view").open()
194208
end
195209
end
196210
end
197211

198-
local auto_close_events = { "event_terminated", "event_exited" }
212+
local auto_close = { "event_terminated", "event_exited" }
199213

200-
for _, event in ipairs(auto_close_events) do
201-
dap.listeners.before[event][SUBSCRIPTION_ID] = function()
214+
for _, listener in ipairs(auto_close) do
215+
dap.listeners.before[listener][SUBSCRIPTION_ID] = function()
202216
if setup.config.auto_toggle then
203217
require("dap-view").close()
204218
end

lua/dap-view/threads/view.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ M.show = function()
2424
return
2525
end
2626

27+
if views.cleanup_view(session.stopped_thread_id == nil, "No stopped thread") then
28+
return
29+
end
30+
2731
if views.cleanup_view(vim.tbl_isempty(session.threads), "Debug adapter returned no threads") then
2832
return
2933
end

0 commit comments

Comments
 (0)