@@ -21,56 +21,61 @@ return function(opts)
2121
2222 local job_started = false
2323 local job_completed = false
24- return void (async (function (prompt , process_result , process_complete )
25- if not job_started then
26- local job_opts = fn_command ()
27-
28- local writer
29- if job_opts .writer and Job .is_job (job_opts .writer ) then
30- writer = job_opts .writer
31- elseif job_opts .writer then
32- writer = Job :new (job_opts .writer )
24+ return setmetatable ({
25+ close = function () end ,
26+ results = results ,
27+ }, {
28+ __call = void (async (function (_ , prompt , process_result , process_complete )
29+ if not job_started then
30+ local job_opts = fn_command ()
31+
32+ local writer
33+ if job_opts .writer and Job .is_job (job_opts .writer ) then
34+ writer = job_opts .writer
35+ elseif job_opts .writer then
36+ writer = Job :new (job_opts .writer )
37+ end
38+
39+ local job = Job :new {
40+ command = job_opts .command ,
41+ args = job_opts .args ,
42+ cwd = job_opts .cwd or cwd ,
43+ maximum_results = opts .maximum_results ,
44+ writer = writer ,
45+ enable_recording = false ,
46+
47+ on_stdout = vim .schedule_wrap (function (_ , line )
48+ num_results = num_results + 1
49+
50+ local v = entry_maker (line )
51+ results [num_results ] = v
52+ process_result (v )
53+ end ),
54+
55+ on_exit = function ()
56+ process_complete ()
57+ job_completed = true
58+ end ,
59+ }
60+
61+ job :start ()
62+ job_started = true
3363 end
3464
35- local job = Job :new {
36- command = job_opts .command ,
37- args = job_opts .args ,
38- cwd = job_opts .cwd or cwd ,
39- maximum_results = opts .maximum_results ,
40- writer = writer ,
41- enable_recording = false ,
42-
43- on_stdout = vim .schedule_wrap (function (_ , line )
44- num_results = num_results + 1
45-
46- local v = entry_maker (line )
47- results [num_results ] = v
48- process_result (v )
49- end ),
50-
51- on_exit = function ()
52- process_complete ()
53- job_completed = true
54- end ,
55- }
56-
57- job :start ()
58- job_started = true
59- end
60-
61- local current_count = num_results
62- for index = 1 , current_count do
63- if process_result (results [index ]) then
64- break
65- end
65+ local current_count = num_results
66+ for index = 1 , current_count do
67+ if process_result (results [index ]) then
68+ break
69+ end
6670
67- if index % AWAITABLE == 0 then
68- await (async_lib .scheduler ())
71+ if index % AWAITABLE == 0 then
72+ await (async_lib .scheduler ())
73+ end
6974 end
70- end
7175
72- if job_completed then
73- process_complete ()
74- end
75- end ))
76+ if job_completed then
77+ process_complete ()
78+ end
79+ end )),
80+ })
7681end
0 commit comments