22local M = {}
33local vc_config = require (" vectorcode.config" )
44local notify_opts = vc_config .notify_opts
5+ local jobrunner = require (" vectorcode.jobrunner.cmd" )
56
67local logger = vc_config .logger
78
@@ -58,37 +59,35 @@ local function async_runner(query_message, buf_nr)
5859 )
5960 vim .list_extend (args , { " --project_root" , project_root })
6061 end
62+
63+ if cache .options .single_job then
64+ kill_jobs (buf_nr )
65+ end
66+
6167 CACHE [buf_nr ].job_count = CACHE [buf_nr ].job_count + 1
6268 logger .debug (" vectorcode default cacher job args: " , args )
63- local job = require (" plenary.job" ):new ({
64- command = " vectorcode" ,
65- args = args ,
66- detached = true ,
67- on_start = function ()
68- if cache .options .single_job then
69- kill_jobs (buf_nr )
70- end
71- end ,
72- on_exit = function (self , code , signal )
69+
70+ -- jobrunner is assumed to be defined at the module level, e.g., local jobrunner = require("vectorcode.jobrunner.cmd")
71+ local job_pid
72+ job_pid = jobrunner .run_async (
73+ args ,
74+ function (json_result , stderr_error , exit_code , signal )
7375 if not M .buf_is_registered (buf_nr ) then
7476 return
7577 end
76- logger .debug (" vectorcode " , buf_name , " default cacher results: " , self : result () )
78+ logger .debug (" vectorcode " , buf_name , " default cacher results: " , json_result )
7779 CACHE [buf_nr ].job_count = CACHE [buf_nr ].job_count - 1
78- CACHE [buf_nr ].jobs [self .pid ] = nil
79- local ok , json = pcall (
80- vim .json .decode ,
81- table.concat (self :result ()) or " []" ,
82- { array = true , object = true }
83- )
84- if not ok or code ~= 0 then
80+ assert (job_pid ~= nil )
81+ CACHE [buf_nr ].jobs [job_pid ] = nil
82+
83+ if exit_code ~= 0 then
8584 vim .schedule (function ()
8685 if CACHE [buf_nr ].options .notify then
8786 if signal == 15 then
8887 vim .notify (" Retrieval aborted." , vim .log .levels .INFO , notify_opts )
8988 else
9089 vim .notify (
91- " Retrieval failed:\n " .. table.concat (self : result () ),
90+ " Retrieval failed:\\ n" .. table.concat (stderr_error , " \n " ),
9291 vim .log .levels .WARN ,
9392 notify_opts
9493 )
@@ -98,7 +97,7 @@ local function async_runner(query_message, buf_nr)
9897 return
9998 end
10099 cache = CACHE [buf_nr ]
101- cache .retrieval = json or {}
100+ cache .retrieval = json_result or {}
102101 vim .schedule (function ()
103102 if cache .options .notify then
104103 vim .notify (
@@ -109,12 +108,15 @@ local function async_runner(query_message, buf_nr)
109108 end
110109 end )
111110 end ,
112- })
113- job :start ()
111+ buf_nr
112+ )
113+
114114 --- @type VectorCode.Cache
115115 cache = CACHE [buf_nr ]
116- cache .last_run = vim .uv .clock_gettime (" realtime" ).sec
117- cache .jobs [job .pid ] = vim .uv .clock_gettime (" realtime" ).sec
116+ if job_pid then
117+ cache .last_run = vim .uv .clock_gettime (" realtime" ).sec
118+ cache .jobs [job_pid ] = vim .uv .clock_gettime (" realtime" ).sec
119+ end
118120 vim .schedule (function ()
119121 if cache .options .notify then
120122 vim .notify (
@@ -313,21 +315,14 @@ end
313315--- @param on_success fun ( out : vim.SystemCompleted )?
314316--- @param on_failure fun ( out : vim.SystemCompleted ?)?
315317function M .async_check (check_item , on_success , on_failure )
316- if not vc_config .has_cli () then
317- if on_failure ~= nil then
318- on_failure ()
319- end
320- return
321- end
322-
323- check_item = check_item or " config"
324- vim .system ({ " vectorcode" , " check" , check_item }, {}, function (out )
325- if out .code == 0 and type (on_success ) == " function" then
326- vim .schedule_wrap (on_success )(out )
327- elseif out .code ~= 0 and type (on_failure ) == " function" then
328- vim .schedule_wrap (on_failure )(out )
329- end
330- end )
318+ vim .deprecate (
319+ " vectorcode.cacher.default.async_check" ,
320+ " vectorcode.cacher.utils.async_check" ,
321+ " 0.7.0" ,
322+ " VectorCode" ,
323+ true
324+ )
325+ require (" vectorcode.cacher" ).utils .async_check (check_item , on_success , on_failure )
331326end
332327
333328--- @param bufnr integer ?
0 commit comments