Skip to content

Commit 1377962

Browse files
committed
fixup: Attempt to clean up some more async items. Next is status
1 parent f4a4535 commit 1377962

3 files changed

Lines changed: 19 additions & 51 deletions

File tree

lua/telescope/pickers.lua

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ function Picker:find()
365365

366366
local status_updater = self:get_status_updater(prompt_win, prompt_bufnr)
367367
local debounced_status = debounce.throttle_leading(status_updater, 50)
368+
-- local debounced_status = status_updater
368369

369370
local tx, rx = channel.mpsc()
370371
self.__on_lines = tx.send
@@ -829,11 +830,6 @@ function Picker:_reset_track()
829830

830831
self.stats.filtered = 0
831832
self.stats.highlights = 0
832-
833-
self.stats._sort_time = 0
834-
self.stats._add_time = 0
835-
self.stats._highlight_time = 0
836-
self.stats._start = vim.loop.hrtime()
837833
end
838834

839835
function Picker:_track(key, func, ...)
@@ -912,11 +908,15 @@ end
912908

913909

914910
function Picker:get_result_processor(find_id, prompt, status_updater)
915-
local score_cb = function(score, entry)
911+
local cb_add = function(score, entry)
916912
self.manager:add_entry(self, score, entry)
917913
status_updater()
918914
end
919915

916+
local cb_filter = function(_)
917+
self:_increment("filtered")
918+
end
919+
920920
return function(entry)
921921
if find_id ~= self._find_id
922922
or self.closed
@@ -944,33 +944,7 @@ function Picker:get_result_processor(find_id, prompt, status_updater)
944944
end
945945
end
946946

947-
self.sorter:score(prompt, entry, score_cb)
948-
949-
-- local sort_ok
950-
-- local sort_score = 0
951-
952-
-- if self.sorter then
953-
-- sort_ok, sort_score = self:_track("_sort_time", pcall, self.sorter.score, self.sorter, prompt, entry)
954-
955-
-- if not sort_ok then
956-
-- log.warn("Sorting failed with:", prompt, entry, sort_score)
957-
-- return
958-
-- end
959-
960-
-- if entry.ignore_count ~= nil and entry.ignore_count == true then
961-
-- self:_decrement("processed")
962-
-- end
963-
964-
-- if sort_score == -1 then
965-
-- self:_increment("filtered")
966-
-- log.trace("Filtering out result: ", entry)
967-
-- return
968-
-- end
969-
-- end
970-
971-
-- self:_track("_add_time", self.manager.add_entry, self.manager, self, sort_score, entry)
972-
973-
-- status_updater()
947+
self.sorter:score(prompt, entry, cb_add, cb_filter)
974948
end
975949
end
976950

@@ -1016,17 +990,6 @@ function Picker:get_result_completor(results_bufnr, find_id, prompt, status_upda
1016990
self:clear_extra_rows(results_bufnr)
1017991
self:highlight_displayed_rows(results_bufnr, prompt)
1018992

1019-
-- TODO: Cleanup.
1020-
self.stats._done = vim.loop.hrtime()
1021-
self.stats.time = (self.stats._done - self.stats._start) / 1e9
1022-
1023-
local function do_times(key)
1024-
self.stats[key] = self.stats["_" .. key] / 1e9
1025-
end
1026-
1027-
do_times("sort_time")
1028-
do_times("add_time")
1029-
do_times("highlight_time")
1030993

1031994
self:_on_complete()
1032995

lua/telescope/sorters.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ end
8282

8383
-- TODO: Consider doing something that makes it so we can skip the filter checks
8484
-- if we're not discarding. Also, that means we don't have to check otherwise as well :)
85-
function Sorter:score(prompt, entry, cb)
85+
function Sorter:score(prompt, entry, cb_add, cb_filter)
8686
if not entry or not entry.ordinal then return end
8787

8888
local ordinal = entry.ordinal
8989
if self:_was_discarded(prompt, ordinal) then
90-
return
90+
return cb_filter(entry)
9191
end
9292

9393
local filter_score
@@ -97,17 +97,17 @@ function Sorter:score(prompt, entry, cb)
9797
end
9898

9999
if filter_score == FILTERED then
100-
return
100+
return cb_filter(entry)
101101
end
102102

103103
local score = self:scoring_function(prompt or "", ordinal, entry)
104104
if score == FILTERED then
105105
self:_mark_discarded(prompt, ordinal)
106-
return
106+
return cb_filter(entry)
107107
end
108108

109-
if cb then
110-
cb(score, entry)
109+
if cb_add then
110+
return cb_add(score, entry)
111111
else
112112
return score
113113
end

lua/tests/automated/telescope_spec.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ describe('telescope', function()
100100
describe('fzy', function()
101101
local sorter = require'telescope.sorters'.get_fzy_sorter()
102102
local function score(prompt, line)
103-
return sorter:score(prompt, {ordinal = line}) or -1
103+
return sorter:score(
104+
prompt,
105+
{ordinal = line},
106+
function(val) return val end,
107+
function() return -1 end
108+
)
104109
end
105110

106111
describe("matches", function()

0 commit comments

Comments
 (0)