telescope-frecency.nvim/lua/frecency/fuzzy_sorter.lua
JINNOUCHI Yasushi c140e6ff9c
feat: make query() faster and more lazier (#241)
* refactor: simplify logic to load web_devicons

* refactor: make register() asynchronous

* fix: load lazily modules outside this plugin

* refactor: simplify logic to wait initialization

* refactor: use uv.hrtime() instead of os.clock()

* fix: avoid errors in calling plenary.log in async

* test: store elapsed time to check in tests

* test: fix module names

This becomes a problem only in Ubuntu because macOS and Windows does not
care cases in filenames.

* test: fix types and unused modules

* style: fix by stylua

* refactor: make recency / entry_maker loaded lazily
2024-08-25 19:28:52 +09:00

28 lines
783 B
Lua

local config = require "frecency.config"
local lazy_require = require "frecency.lazy_require"
local sorters = lazy_require "telescope.sorters"
---@param opts any options for get_fzy_sorter()
return function(opts)
local fzy_sorter = sorters.get_fzy_sorter(opts)
return sorters.Sorter:new {
---@param prompt string
---@param entry FrecencyEntry
---@return number
scoring_function = function(_, prompt, _, entry)
if #prompt == 0 then
return 1
end
local fzy_score = fzy_sorter:scoring_function(prompt, entry.ordinal)
if fzy_score <= 0 then
return -1
end
entry.fuzzy_score = config.scoring_function(entry.score, fzy_score)
return entry.fuzzy_score
end,
highlighter = fzy_sorter.highlighter,
}
end