Skip to content

Commit da8ea7f

Browse files
committed
fix: Move back towards more backwards compat methods
1 parent 69b7f4e commit da8ea7f

4 files changed

Lines changed: 106 additions & 96 deletions

File tree

lua/telescope/finders/async_job_finder.lua

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,49 @@ return function(opts)
2525
end
2626

2727
local job
28-
return void(async(function(prompt, process_result, process_complete, picker)
29-
print("are we callin anything?", job)
30-
if job and not job.is_shutdown then
31-
log.debug("Shutting down old job")
32-
job:shutdown()
33-
end
34-
35-
local job_opts = fn_command(prompt)
36-
if not job_opts then return end
28+
return setmetatable({
29+
close = function() end,
30+
}, {
31+
__call = void(async(function(prompt, process_result, process_complete)
32+
print("are we callin anything?", job)
33+
if job and not job.is_shutdown then
34+
log.debug("Shutting down old job")
35+
job:shutdown()
36+
end
3737

38-
local writer = nil
39-
if job_opts.writer and Job.is_job(job_opts.writer) then
40-
writer = job_opts.writer
41-
elseif opts.writer then
42-
writer = Job:new(job_opts.writer)
43-
end
38+
local job_opts = fn_command(prompt)
39+
if not job_opts then return end
4440

45-
job = Job:new {
46-
command = job_opts.command,
47-
args = job_opts.args,
48-
cwd = job_opts.cwd or opts.cwd,
49-
maximum_results = opts.maximum_results,
50-
writer = writer,
51-
enable_recording = false,
41+
local writer = nil
42+
if job_opts.writer and Job.is_job(job_opts.writer) then
43+
writer = job_opts.writer
44+
elseif opts.writer then
45+
writer = Job:new(job_opts.writer)
46+
end
5247

53-
on_stdout = vim.schedule_wrap(function(_, line)
54-
if picker and prompt ~= picker:_get_prompt() then
55-
-- TODO: Should make ez cancel for job.
56-
return
57-
end
48+
job = Job:new {
49+
command = job_opts.command,
50+
args = job_opts.args,
51+
cwd = job_opts.cwd or opts.cwd,
52+
maximum_results = opts.maximum_results,
53+
writer = writer,
54+
enable_recording = false,
5855

59-
if not line or line == "" then
60-
return
61-
end
56+
on_stdout = vim.schedule_wrap(function(_, line)
57+
if not line or line == "" then
58+
return
59+
end
6260

63-
process_result(entry_maker(line))
64-
end),
61+
-- TODO: shutdown job here.
62+
process_result(entry_maker(line))
63+
end),
6564

66-
on_exit = function()
67-
process_complete()
68-
end,
69-
}
65+
on_exit = function()
66+
process_complete()
67+
end,
68+
}
7069

71-
job:start()
72-
end))
70+
job:start()
71+
end)),
72+
})
7373
end

lua/telescope/finders/async_oneshot_finder.lua

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
})
7681
end

lua/telescope/finders/async_static_finder.lua

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@ return function(opts)
2222
end
2323
end
2424

25-
return void(async(function(_, process_result, process_complete)
26-
for i, v in ipairs(results) do
27-
if process_result(v) then break end
28-
29-
if i % 1000 == 0 then
30-
await(async_lib.scheduler())
25+
return setmetatable({
26+
results = results,
27+
close = function() end,
28+
}, {
29+
__call = void(async(function(_, _, process_result, process_complete)
30+
for i, v in ipairs(results) do
31+
if process_result(v) then break end
32+
33+
if i % 1000 == 0 then
34+
await(async_lib.scheduler())
35+
end
3136
end
32-
end
3337

34-
process_complete()
35-
end))
38+
process_complete()
39+
end)),
40+
})
3641
end

lua/telescope/previewers/buffer_previewer.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ previewers.git_file_diff = defaulter(function(opts)
544544
}
545545
end, {})
546546

547-
previewers.autocommands = defaulter(function(opts)
547+
previewers.autocommands = defaulter(function(_)
548548
return previewers.new_buffer_previewer {
549549
teardown = function(self)
550550
if self.state and self.state.last_set_bufnr and vim.api.nvim_buf_is_valid(self.state.last_set_bufnr) then
@@ -559,7 +559,7 @@ previewers.autocommands = defaulter(function(opts)
559559
define_preview = function(self, entry, status)
560560
local results = vim.tbl_filter(function (x)
561561
return x.group == entry.group
562-
end, opts.results)
562+
end, status.picker.finder.results)
563563

564564
if self.state.last_set_bufnr then
565565
pcall(vim.api.nvim_buf_clear_namespace, self.state.last_set_bufnr, ns_previewer, 0, -1)

0 commit comments

Comments
 (0)