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 (
0 commit comments