Skip to content

Commit 8adb3bc

Browse files
committed
fix: Attempt to fix incompatibility with grepprg values
1 parent 11a99e8 commit 8adb3bc

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

lua/debugprint/init.lua

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,37 @@ end
440440

441441
---@return nil
442442
M.debug_print_qf_list = function()
443+
local grep_cmd = vim.o.grepprg
444+
local search_args = '"' .. global_opts.print_tag .. '" ' .. vim.fn.getcwd()
445+
446+
local cannot_run = function()
447+
vim.notify(
448+
"Warning: grepprg does not contain $* placeholder, cannot run command",
449+
vim.log.levels.WARN
450+
)
451+
end
452+
453+
-- The standard setups for 'rg' and 'grep' for grepprg seem to be
454+
-- incompatible for recursive searches, which is very annoying - FIXME:
455+
-- raise a NeoVim bug on this.
456+
if grep_cmd:find("^rg") then
457+
grep_cmd = grep_cmd .. " " .. search_args
458+
else
459+
if not grep_cmd:find("%$%*") then
460+
cannot_run()
461+
return
462+
end
463+
464+
if grep_cmd:find("^grep") then
465+
grep_cmd = grep_cmd:gsub("%$%*", "-r " .. search_args)
466+
else
467+
grep_cmd = grep_cmd:gsub("%$%*", search_args)
468+
end
469+
end
470+
443471
vim.fn.setqflist({}, " ", {
444472
title = "Debug Prints",
445-
lines = vim.fn.systemlist(
446-
vim.o.grepprg
447-
.. ' "'
448-
.. global_opts.print_tag
449-
.. '" '
450-
.. vim.fn.getcwd()
451-
),
473+
lines = vim.fn.systemlist(grep_cmd),
452474
efm = "%f:%l:%m",
453475
})
454476
vim.cmd("copen")

tests/debugprint.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,6 @@ describe("quickfix list", function()
21702170
vim.cmd("DebugPrintQFList")
21712171

21722172
local qflist = vim.fn.getqflist()
2173-
print('DEBUGPRINT[1]: debugprint.lua:2172: qflist=' .. vim.inspect(qflist))
21742173
assert.equals(#qflist, 1)
21752174
assert.True(string.find(qflist[1].text, "DEBUGPRINT") > 0)
21762175
end)

0 commit comments

Comments
 (0)