2
2
-- Dispatcher handles the communication between the plugin and LLM providers.
3
3
---- ----------------------------------------------------------------------------
4
4
5
+ local uv = vim .uv or vim .loop
6
+
5
7
local logger = require (" gp.logger" )
6
8
local tasker = require (" gp.tasker" )
7
9
local vault = require (" gp.vault" )
@@ -18,7 +20,7 @@ local D = {
18
20
19
21
--- @param opts table # user config
20
22
D .setup = function (opts )
21
- logger .debug (" dispatcher setup started\n " .. vim .inspect (opts ))
23
+ logger .debug (" dispatcher: setup started\n " .. vim .inspect (opts ))
22
24
23
25
D .config .curl_params = opts .curl_params or default_config .curl_params
24
26
@@ -52,9 +54,26 @@ D.setup = function(opts)
52
54
53
55
D .query_dir = helpers .prepare_dir (D .query_dir , " query store" )
54
56
55
- local files = vim .fn .glob (D .query_dir .. " /*.json" , false , true )
57
+ local files = {}
58
+ local handle = uv .fs_scandir (D .query_dir )
59
+ if handle then
60
+ local name , type
61
+ while true do
62
+ name , type = uv .fs_scandir_next (handle )
63
+ if not name then
64
+ break
65
+ end
66
+ local path = D .query_dir .. " /" .. name
67
+ type = type or uv .fs_stat (path ).type
68
+ if type == " file" and name :match (" %.json$" ) then
69
+ table.insert (files , path )
70
+ end
71
+ end
72
+ end
73
+
74
+ logger .debug (" dispatcher: query files: " .. # files )
56
75
if # files > 200 then
57
- logger .debug (" too many query files, truncating cache" )
76
+ logger .debug (" dispatcher: too many query files, truncating cache" )
58
77
table.sort (files , function (a , b )
59
78
return a > b
60
79
end )
@@ -63,7 +82,7 @@ D.setup = function(opts)
63
82
end
64
83
end
65
84
66
- logger .debug (" dispatcher setup finished\n " .. vim .inspect (D ))
85
+ logger .debug (" dispatcher: setup finished\n " .. vim .inspect (D ))
67
86
end
68
87
69
88
--- @param messages table
0 commit comments