From 96cac0a8c861d5cdb1bb7765cc2d20e47ebb7885 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 3 Aug 2020 20:40:04 -0400 Subject: Work on ngram sorter --- lua/telescope/finders.lua | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'lua/telescope/finders.lua') diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua index 518dfc1..e5a601e 100644 --- a/lua/telescope/finders.lua +++ b/lua/telescope/finders.lua @@ -1,4 +1,5 @@ local a = vim.api +local log = require('telescope.log') local finders = {} @@ -29,7 +30,7 @@ function Finder:new(opts) -- ... return setmetatable({ fn_command = opts.fn_command, - responsive = opts.responsive, + static = opts.static, state = {}, job_id = -1, }, Finder) @@ -44,11 +45,28 @@ end -- process_search -- do_your_job -- process_plz -function Finder:_find(prompt, process_result) +function Finder:_find(prompt, process_result, process_complete) if (self.state.job_id or 0) > 0 then vim.fn.jobstop(self.job_id) end + log.info("Finding...") + if self.static and self.done then + log.info("Using previous results") + for _, v in ipairs(self._cached_lines) do + process_result(v) + end + + process_complete() + return + end + + if self.static then + self._cached_lines = {} + end + + self.done = false + -- TODO: How to just literally pass a list... -- TODO: How to configure what should happen here -- TODO: How to run this over and over? @@ -57,9 +75,21 @@ function Finder:_find(prompt, process_result) on_stdout = function(_, data, _) for _, line in ipairs(data) do - process_result(line) + if vim.trim(line) ~= "" then + process_result(line) + + if self.static then + table.insert(self._cached_lines, line) + end + end end - end + end, + + on_exit = function() + self.done = true + + process_complete() + end, }) end -- cgit v1.2.3