diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-10-08 22:31:44 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-10-08 22:31:44 -0400 |
| commit | 59497d664086c4c7aa24a15a1c3b9ccf718ce9c7 (patch) | |
| tree | fc418ff9dbfd96579ccb897c0f15f47c19894bb6 /lua/telescope/sorters.lua | |
| parent | 7938ace0f6681e5bd5207283036b496416879c67 (diff) | |
feat: Do a bit better sorting for command history
To be honest, I'm not 100% sure this is fantastic, but it's definitely a
step in the right direction for command history.
Closes: #150
Diffstat (limited to 'lua/telescope/sorters.lua')
| -rw-r--r-- | lua/telescope/sorters.lua | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lua/telescope/sorters.lua b/lua/telescope/sorters.lua index 3f9844d..4088ce0 100644 --- a/lua/telescope/sorters.lua +++ b/lua/telescope/sorters.lua @@ -198,7 +198,7 @@ end sorters.get_generic_fuzzy_sorter = function(opts) opts = opts or {} - local ngram_len = 2 + local ngram_len = opts.ngram_len or 2 local function overlapping_ngrams(s, n) if TelescopeCachedNgrams[s] and TelescopeCachedNgrams[s][n] then @@ -283,6 +283,30 @@ sorters.get_generic_fuzzy_sorter = function(opts) } end +sorters.fuzzy_with_index_bias = function(opts) + opts = opts or {} + opts.ngram_len = 2 + + -- TODO: Probably could use a better sorter here. + local fuzzy_sorter = sorters.get_generic_fuzzy_sorter(opts) + + return Sorter:new { + scoring_function = function(_, prompt, _, entry) + local base_score = fuzzy_sorter:score(prompt, entry) + + if base_score == -1 then + return -1 + end + + if base_score == 0 then + return entry.index + else + return math.min(math.pow(entry.index, 0.25), 2) * base_score + end + end + } +end + -- Bad & Dumb Sorter sorters.get_levenshtein_sorter = function() return Sorter:new { |
