11describe (" peekstack.providers.grep" , function ()
22 local grep = require (" peekstack.providers.grep" )
3+ local original_notify
4+ local original_system
5+ local original_input
6+ local notifications
7+
8+ before_each (function ()
9+ original_notify = vim .notify
10+ original_system = vim .system
11+ original_input = vim .ui .input
12+ notifications = {}
13+ vim .notify = function (msg , level )
14+ table.insert (notifications , { msg = msg , level = level })
15+ end
16+ end )
17+
18+ after_each (function ()
19+ vim .notify = original_notify
20+ vim .system = original_system
21+ vim .ui .input = original_input
22+ end )
323
424 it (" parses vimgrep output with Unix paths" , function ()
525 local output = " /tmp/sample.lua:3:5:hello"
@@ -23,4 +43,41 @@ describe("peekstack.providers.grep", function()
2343 assert .equals (" hit" , items [1 ].text )
2444 assert .is_true (items [1 ].uri :find (" sample.lua" , 1 , true ) ~= nil )
2545 end )
46+
47+ it (" formats ignore-file failures with a targeted hint" , function ()
48+ local message = grep ._format_failure_message (" error reading .gitignore: invalid UTF-8" )
49+
50+ assert .equals (
51+ " rg failed; check .gitignore/.ignore patterns or encoding: error reading .gitignore: invalid UTF-8" ,
52+ message
53+ )
54+ end )
55+
56+ it (" warns with the ignore hint when rg reports ignore file issues" , function ()
57+ local items = nil
58+
59+ vim .ui .input = function (_ , cb )
60+ cb (" sample" )
61+ end
62+ vim .system = function (_ , _ , cb )
63+ cb ({
64+ code = 2 ,
65+ stdout = " " ,
66+ stderr = " error reading .ignore: invalid UTF-8" ,
67+ })
68+ end
69+
70+ grep .search ({}, function (result )
71+ items = result
72+ end )
73+
74+ vim .wait (100 , function ()
75+ return items ~= nil
76+ end )
77+
78+ assert .equals (0 , # items )
79+ assert .equals (1 , # notifications )
80+ assert .equals (vim .log .levels .WARN , notifications [1 ].level )
81+ assert .is_true (notifications [1 ].msg :find (" check .gitignore/.ignore patterns or encoding" , 1 , true ) ~= nil )
82+ end )
2683end )
0 commit comments