22-- Dispatcher handles the communication between the plugin and LLM providers.
33---- ----------------------------------------------------------------------------
44
5+ local uv = vim .uv or vim .loop
6+
57local logger = require (" gp.logger" )
68local tasker = require (" gp.tasker" )
79local vault = require (" gp.vault" )
@@ -18,7 +20,7 @@ local D = {
1820
1921--- @param opts table # user config
2022D .setup = function (opts )
21- logger .debug (" dispatcher setup started\n " .. vim .inspect (opts ))
23+ logger .debug (" dispatcher: setup started\n " .. vim .inspect (opts ))
2224
2325 D .config .curl_params = opts .curl_params or default_config .curl_params
2426
@@ -52,9 +54,26 @@ D.setup = function(opts)
5254
5355 D .query_dir = helpers .prepare_dir (D .query_dir , " query store" )
5456
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 )
5675 if # files > 200 then
57- logger .debug (" too many query files, truncating cache" )
76+ logger .debug (" dispatcher: too many query files, truncating cache" )
5877 table.sort (files , function (a , b )
5978 return a > b
6079 end )
@@ -63,7 +82,7 @@ D.setup = function(opts)
6382 end
6483 end
6584
66- logger .debug (" dispatcher setup finished\n " .. vim .inspect (D ))
85+ logger .debug (" dispatcher: setup finished\n " .. vim .inspect (D ))
6786end
6887
6988--- @param messages table
0 commit comments