From a97af306c4e9c9a6fa7c886c0ffe3079822c5203 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 20 Aug 2021 11:11:24 -0400 Subject: 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. --- lua/telescope/finders.lua | 55 ++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'lua/telescope/finders.lua') 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 {} -- cgit v1.2.3