summaryrefslogtreecommitdiff
path: root/lua/telescope/finders.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2021-08-20 11:11:24 -0400
committerGitHub <noreply@github.com>2021-08-20 11:11:24 -0400
commita97af306c4e9c9a6fa7c886c0ffe3079822c5203 (patch)
treef5e2b50a767e93618d0d8fdddb8a964c90633c8a /lua/telescope/finders.lua
parentd6d28dbe324de9826a579155076873888169ba0f (diff)
feat(performance): Major performance improvements using async v2 from @oberblastmeister (#987)
* start: Working w/ async jobs * short circuit to using bad finder if you pass writer.
Diffstat (limited to 'lua/telescope/finders.lua')
-rw-r--r--lua/telescope/finders.lua55
1 files changed, 19 insertions, 36 deletions
diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua
index 7fecd67..ea4b88b 100644
--- a/lua/telescope/finders.lua
+++ b/lua/telescope/finders.lua
@@ -2,12 +2,10 @@ local Job = require "plenary.job"
local make_entry = require "telescope.make_entry"
local log = require "telescope.log"
-local a = require "plenary.async_lib"
-local await = a.await
local async_static_finder = require "telescope.finders.async_static_finder"
local async_oneshot_finder = require "telescope.finders.async_oneshot_finder"
--- local async_job_finder = require('telescope.finders.async_job_finder')
+local async_job_finder = require "telescope.finders.async_job_finder"
local finders = {}
@@ -103,7 +101,7 @@ function JobFinder:_find(prompt, process_result, process_complete)
enable_recording = false,
on_stdout = on_output,
- on_stderr = on_output,
+ -- on_stderr = on_output,
on_exit = function()
process_complete()
@@ -131,17 +129,15 @@ function DynamicFinder:new(opts)
end
function DynamicFinder:_find(prompt, process_result, process_complete)
- a.scope(function()
- local results = await(self.fn(prompt))
+ local results = self.fn(prompt)
- for _, result in ipairs(results) do
- if process_result(self.entry_maker(result)) then
- return
- end
+ for _, result in ipairs(results) do
+ if process_result(self.entry_maker(result)) then
+ return
end
+ end
- process_complete()
- end)
+ process_complete()
end
--- Return a new Finder
@@ -154,31 +150,18 @@ finders._new = function(opts)
return JobFinder:new(opts)
end
-finders.new_job = function(command_generator, entry_maker, maximum_results, cwd)
- -- return async_job_finder {
- -- command_generator = command_generator,
- -- entry_maker = entry_maker,
- -- maximum_results = maximum_results,
- -- cwd = cwd,
- -- }
-
- return JobFinder:new {
- fn_command = function(_, prompt)
- local command_list = command_generator(prompt)
- if command_list == nil then
- return nil
- end
-
- local command = table.remove(command_list, 1)
+finders.new_async_job = function(opts)
+ if opts.writer then
+ return finders._new(opts)
+ end
- return {
- command = command,
- args = command_list,
- }
- end,
+ return async_job_finder(opts)
+end
+finders.new_job = function(command_generator, entry_maker, _, cwd)
+ return async_job_finder {
+ command_generator = command_generator,
entry_maker = entry_maker,
- maximum_results = maximum_results,
cwd = cwd,
}
end
@@ -186,8 +169,8 @@ end
--- One shot job
---@param command_list string[]: Command list to execute.
---@param opts table: stuff
---- @key entry_maker function Optional: function(line: string) => table
---- @key cwd string
+-- @key entry_maker function Optional: function(line: string) => table
+-- @key cwd string
finders.new_oneshot_job = function(command_list, opts)
opts = opts or {}