Skip to content

Commit cea95aa

Browse files
committed
fix: simplify scoring logic and tests
1 parent d989499 commit cea95aa

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

lua/telescope/sorters.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ end
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 :)
8585
function Sorter:score(prompt, entry, cb)
86-
if not entry or not entry.ordinal then return -1 end
86+
if not entry or not entry.ordinal then return end
8787

8888
local ordinal = entry.ordinal
89-
9089
if self:_was_discarded(prompt, ordinal) then
9190
return
9291
end
@@ -97,18 +96,21 @@ function Sorter:score(prompt, entry, cb)
9796
filter_score, prompt = self:filter_function(prompt, entry)
9897
end
9998

100-
local score = (filter_score == FILTERED and FILTERED or
101-
self:scoring_function(prompt or "", ordinal, entry))
102-
103-
if score == FILTERED then
104-
self:_mark_discarded(prompt, ordinal)
99+
if filter_score == FILTERED then
100+
return
105101
end
106102

103+
local score = self:scoring_function(prompt or "", ordinal, entry)
107104
if score == FILTERED then
105+
self:_mark_discarded(prompt, ordinal)
108106
return
109107
end
110108

111-
cb(score, entry)
109+
if cb then
110+
cb(score, entry)
111+
else
112+
return score
113+
end
112114
end
113115

114116
function Sorter:_was_discarded(prompt, ordinal)

lua/tests/automated/telescope_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ 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})
103+
return sorter:score(prompt, {ordinal = line}) or -1
104104
end
105105

106106
describe("matches", function()

0 commit comments

Comments
 (0)