Skip to content

Commit 6274055

Browse files
committed
feat: Support DebugPrintQFList
1 parent a64495c commit 6274055

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ the NeoVim generation. It:
5454
lines.
5555

5656
- Provides [commands](#keymappings-and-commands) to delete or comment debugging
57-
lines added to the current buffer, and search for those lines in the current directory
58-
(project) using fzf-lua or telescope.
57+
lines added to the current buffer, search for those lines in the current directory
58+
(project) using fzf-lua or telescope, and add those lines to the quickfix
59+
list.
5960

6061
- Can optionally move to the inserted line (or not).
6162

@@ -131,6 +132,7 @@ following table.
131132
| Command | `:ToggleCommentDebugPrints` | Comment/uncomment debug lines in buffer | - |
132133
| Command | `:ResetDebugPrintsCounter` | Reset debug print persistent counter (only for built-in counter implementation) | - |
133134
| Command | `:SearchDebugPrints` | Search for all debug print lines in the current directory using fzf-lua or telescope.nvim | - |
135+
| Command | `:DebugPrintQFList` | Search for all debug print lines in the current directory and populate quickfix list | - |
134136

135137
Each of the keymappings (except for 'surround' keys and insert modes) can also
136138
be prefixed with a register, see the [showcase](SHOWCASE.md#register-usage) for
@@ -256,7 +258,8 @@ they are used to convert sections to ROT-13, which most folks don't use.
256258
| Comment/uncomment all debug lines in buffer | :+1: | :+1: | :x: | :x: | :x: | :x: | :x: |
257259
| Comment/uncomment all debug lines in selected range | :+1: | :x: | :x: | :x: | :x: | :x: | :x: |
258260
| Can put debugprint text into register | :+1: | :x: | :x: | :+1: | :x: | :x: | :x: |
259-
| Search for debugprint lines in the current directory using fzf-lua | :+1: | :x: | :x: | :x: | :x: | :x: | :x: |
261+
| Search for debugprint lines using fzf-lua or telescope | :+1: | :x: | :x: | :x: | :x: | :x: | :x: |
262+
| Search for debugprint lines and populate quickfix list | :+1: | :x: | :x: | :x: | :x: | :x: | :x: |
260263
| Extra visual emphasis of log statements | :+1: Highlights inserted lines | :+1: Flashes to highlight lines on insertion | :+1: status line counter, signcolumn, line-highlight, scrollbar | :x: | :x: | :x: | :x: |
261264
| Can insert logs in batches | :+1: (using registers) | :+1: | :x: | :x: | :x: | :x: | :x: |
262265
| Log watcher mechanism | :x: | :+1: | :x: | :x: | :x: | :x: | :x: |

lua/debugprint/init.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,16 @@ M.show_debug_prints_fzf = function()
438438
)
439439
end
440440

441+
---@return nil
442+
M.debug_print_qf_list = function()
443+
vim.fn.setqflist({}, ' ', {
444+
title = 'Debug Prints',
445+
lines = vim.fn.systemlist(vim.o.grepprg .. ' "' .. global_opts.print_tag .. '" ' .. vim.fn.getcwd()),
446+
efm = '%f:%l:%m'
447+
})
448+
vim.cmd('copen')
449+
end
450+
441451
if vim.fn.has("nvim-0.10.0") ~= 1 then
442452
vim.notify_once(
443453
"debugprint.nvim is only compatible with NeoVim 0.10+",

lua/debugprint/options.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ local GLOBAL_OPTION_DEFAULTS = {
3333
delete_debug_prints = "DeleteDebugPrints",
3434
reset_debug_prints_counter = "ResetDebugPrintsCounter",
3535
search_debug_prints = "SearchDebugPrints",
36+
debug_print_qf_list = "DebugPrintQFList",
3637
},
3738
display_counter = true,
3839
display_location = true,

lua/debugprint/setup.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ M.map_keys_and_commands = function(global_opts)
210210
desc = "Search for debug prints using fzf-lua or telescope.nvim",
211211
}
212212
)
213+
214+
create_command(
215+
global_opts.commands.debug_print_qf_list,
216+
require("debugprint").debug_print_qf_list,
217+
{
218+
desc = "Search for debug prints and populate quickfix list",
219+
}
220+
)
213221
end
214222

215223
return M

lua/debugprint/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
---@field toggle_comment_debug_prints? string|false
7171
---@field reset_debug_prints_counter? string|false
7272
---@field search_debug_prints? string|false
73+
---@field debug_print_qf_list? string|false
7374

7475
---@class debugprint.FunctionOptions
7576
---@field above? boolean

tests/debugprint.lua

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ end
4848
local init_file = function(lines, extension, row, col, opts)
4949
opts = opts or {}
5050

51-
local tempfile = vim.fn.tempname() .. "." .. extension
51+
local tempfile
52+
53+
if opts.create_in_dir then
54+
local dir = vim.fn.tempname()
55+
vim.fn.mkdir(dir, "p")
56+
tempfile = vim.fs.joinpath(dir, "tmpfile." .. extension)
57+
vim.cmd("cd " .. dir)
58+
else
59+
tempfile = vim.fn.tempname() .. "." .. extension
60+
end
61+
5262
vim.cmd("split " .. tempfile)
5363
vim.cmd("only")
5464
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
@@ -2135,6 +2145,36 @@ describe("comment toggle", function()
21352145
end)
21362146
end)
21372147

2148+
describe("quickfix list", function()
2149+
before_each(function()
2150+
debugprint.setup()
2151+
end)
2152+
2153+
after_each(teardown)
2154+
2155+
it("can use DebugPrintQFList command", function()
2156+
local filename = init_file({
2157+
"foo",
2158+
"bar",
2159+
}, "lua", 1, 0, { create_in_dir = true })
2160+
2161+
feedkeys("g?p")
2162+
vim.cmd("write!")
2163+
2164+
check_lines({
2165+
"foo",
2166+
"print('DEBUGPRINT[1]: " .. filename .. ":1 (after foo)')",
2167+
"bar",
2168+
})
2169+
2170+
vim.cmd("DebugPrintQFList")
2171+
2172+
local qflist = vim.fn.getqflist()
2173+
assert.equals(#qflist, 1)
2174+
assert.True(string.find(qflist[1].text, "DEBUGPRINT") > 0)
2175+
end)
2176+
end)
2177+
21382178
describe("handle deprecated options, create_keymaps=false", function()
21392179
before_each(function()
21402180
debugprint.setup({ create_keymaps = false })

0 commit comments

Comments
 (0)