Skip to content

Commit a186abf

Browse files
committed
feat(threads): filter threads by name
1 parent 2582a97 commit a186abf

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

lua/dap-view/state.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
---@field winnr? integer
2525
---@field term_bufnrs {[number]: number}
2626
---@field term_winnr? integer
27+
---@field threads_filter string
28+
---@field threads_filter_invert boolean
2729
---@field current_adapter? string
2830
---@field subtle_frames boolean
2931
---@field current_section? dapview.Section
@@ -38,6 +40,8 @@
3840
---@field cur_pos table<dapview.DefaultSection,integer?>
3941
local M = {
4042
term_bufnrs = {},
43+
threads_filter = "",
44+
threads_filter_invert = false,
4145
exceptions_options = {},
4246
stack_trace_errors = {},
4347
frames_by_line = {},

lua/dap-view/threads/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ M.jump_or_noop = function(lnum)
2020
session:_frame_set(frame)
2121
end
2222
else
23-
vim.notify("Can't jump to a thread", log.INFO)
23+
vim.notify("Can only jump to a thread", log.INFO)
2424
end
2525
end
2626

lua/dap-view/threads/view.lua

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ M.show = function()
3333

3434
local line = 0
3535

36+
if state.threads_filter ~= "" then
37+
local filter = "󰈲 "
38+
filter = filter .. state.threads_filter
39+
if state.threads_filter_invert then
40+
filter = filter .. ""
41+
end
42+
api.nvim_buf_set_lines(state.bufnr, line, line, true, { filter })
43+
line = line + 1
44+
end
45+
3646
for k, thread in pairs(session.threads) do
3747
local is_stopped_thread = session.stopped_thread_id == thread.id
3848
local thread_name = is_stopped_thread and thread.name .. "" or thread.name
@@ -79,7 +89,19 @@ M.show = function()
7989
end
8090
)
8191

82-
local content = vim.iter(frames)
92+
local filtered_frames = vim.iter(frames)
93+
:filter(
94+
---@param f {label: string, id: number}
95+
function(f)
96+
local match = f.label:match(state.threads_filter)
97+
local invert = state.threads_filter_invert
98+
local inv_match = invert and not match and not state.threads_filter ~= ""
99+
return inv_match or (not invert and match)
100+
end
101+
)
102+
:totable()
103+
104+
local content = vim.iter(filtered_frames)
83105
:map(
84106
---@param f {label: string, id: number}
85107
function(f)
@@ -90,7 +112,7 @@ M.show = function()
90112

91113
api.nvim_buf_set_lines(state.bufnr, line, line + #content, false, content)
92114

93-
for i, f in pairs(frames) do
115+
for i, f in pairs(filtered_frames) do
94116
local first_pipe_pos = string.find(f.label, "|")
95117
assert(first_pipe_pos, "missing pipe, buffer may have been edited")
96118

lua/dap-view/views/keymaps/docs.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ M.show_help = function()
3434
"## Threads",
3535
"`<CR>` Jump to a frame",
3636
" `t` Toggle subtle frames",
37+
" `f` Filter threads",
38+
" `i` Invert filter",
3739
"## Breakpoints",
3840
"`<CR>` Jump to a breakpoint",
3941
" `d` Delete a breakpoint",

lua/dap-view/views/keymaps/init.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ M.set_keymaps = function()
7070
end
7171
end)
7272

73+
keymap("f", function()
74+
if state.current_section == "threads" then
75+
vim.ui.input({ prompt = "Filter: ", default = state.threads_filter }, function(input)
76+
if input then
77+
state.threads_filter = input
78+
79+
threads_view.show()
80+
end
81+
end)
82+
end
83+
end)
84+
85+
keymap("i", function()
86+
if state.current_section == "threads" then
87+
state.threads_filter_invert = not state.threads_filter_invert
88+
89+
threads_view.show()
90+
end
91+
end)
92+
7393
keymap("c", function()
7494
if state.current_section == "watches" then
7595
local cursor_line = api.nvim_win_get_cursor(state.winnr)[1]

0 commit comments

Comments
 (0)