summaryrefslogtreecommitdiff
path: root/lua/telescope/finders/async_static_finder.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2021-04-08 10:35:44 -0400
committerGitHub <noreply@github.com>2021-04-08 10:35:44 -0400
commit64e59060b1750d0c86761693b6847c3db07afcd2 (patch)
tree13e8c0117cdff926e7bbf107f5496c733329cfb7 /lua/telescope/finders/async_static_finder.lua
parente5fbe6fe60149af8fdeef0d07cba06c029258ba0 (diff)
feat: asyncify pickers - except for live_grep (#709)
* something kind of works already * yayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayaya * use async for everything besides live jobs * fix: fixup autocmds previewer * fix: lints for prime * temp: Add example of how we can think about async sorters * feat: Allow picker to decide when to cancel * fix: simplify scoring logic and tests * fixup: name * fix: Move back towards more backwards compat methods * fixup: Remove results from opts * fixup: remove trailing quote * fixup: Attempt to clean up some more async items. Next is status * wip: Add todo for when bfredl implements extmarks over the EOL * wip * fixup: got em * fixup: cleaning * fixup: docs
Diffstat (limited to 'lua/telescope/finders/async_static_finder.lua')
-rw-r--r--lua/telescope/finders/async_static_finder.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/lua/telescope/finders/async_static_finder.lua b/lua/telescope/finders/async_static_finder.lua
new file mode 100644
index 0000000..0756551
--- /dev/null
+++ b/lua/telescope/finders/async_static_finder.lua
@@ -0,0 +1,41 @@
+local async_lib = require('plenary.async_lib')
+local async = async_lib.async
+local await = async_lib.await
+local void = async_lib.void
+
+local make_entry = require('telescope.make_entry')
+
+return function(opts)
+ local input_results
+ if vim.tbl_islist(opts) then input_results = opts
+ else input_results = opts.results end
+
+ local entry_maker = opts.entry_maker or make_entry.gen_from_string()
+
+ local results = {}
+ for k, v in ipairs(input_results) do
+ local entry = entry_maker(v)
+
+ if entry then
+ entry.index = k
+ table.insert(results, entry)
+ end
+ end
+
+ return setmetatable({
+ results = results,
+ close = function() end,
+ }, {
+ __call = void(async(function(_, _, process_result, process_complete)
+ for i, v in ipairs(results) do
+ if process_result(v) then break end
+
+ if i % 1000 == 0 then
+ await(async_lib.scheduler())
+ end
+ end
+
+ process_complete()
+ end)),
+ })
+end