diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2021-08-20 11:11:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-20 11:11:24 -0400 |
| commit | a97af306c4e9c9a6fa7c886c0ffe3079822c5203 (patch) | |
| tree | f5e2b50a767e93618d0d8fdddb8a964c90633c8a /lua/telescope/sorters.lua | |
| parent | d6d28dbe324de9826a579155076873888169ba0f (diff) | |
feat(performance): Major performance improvements using async v2 from @oberblastmeister (#987)
* start: Working w/ async jobs
* short circuit to using bad finder if you pass writer.
Diffstat (limited to 'lua/telescope/sorters.lua')
| -rw-r--r-- | lua/telescope/sorters.lua | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/lua/telescope/sorters.lua b/lua/telescope/sorters.lua index 8874287..ba38e2d 100644 --- a/lua/telescope/sorters.lua +++ b/lua/telescope/sorters.lua @@ -96,10 +96,10 @@ function Sorter:_start(prompt) local len_previous = #previous if #prompt < len_previous then - log.debug "Reset discard because shorter prompt" + log.trace "Reset discard because shorter prompt" self._discard_state.filtered = {} elseif string.sub(prompt, 1, len_previous) ~= previous then - log.debug "Reset discard no match" + log.trace "Reset discard no match" self._discard_state.filtered = {} end @@ -167,11 +167,10 @@ end sorters.Sorter = Sorter -TelescopeCachedTails = TelescopeCachedTails or nil -if not TelescopeCachedTails then +local make_cached_tail = function() local os_sep = util.get_separator() local match_string = "[^" .. os_sep .. "]*$" - TelescopeCachedTails = setmetatable({}, { + return setmetatable({}, { __index = function(t, k) local tail = string.match(k, match_string) @@ -181,8 +180,8 @@ if not TelescopeCachedTails then }) end -TelescopeCachedUppers = TelescopeCachedUppers - or setmetatable({}, { +local make_cached_uppers = function() + return setmetatable({}, { __index = function(t, k) local obj = {} for i = 1, #k do @@ -196,8 +195,7 @@ TelescopeCachedUppers = TelescopeCachedUppers return obj end, }) - -TelescopeCachedNgrams = TelescopeCachedNgrams or {} +end -- TODO: Match on upper case words -- TODO: Match on last match @@ -206,9 +204,11 @@ sorters.get_fuzzy_file = function(opts) local ngram_len = opts.ngram_len or 2 + local cached_ngrams = {} + local function overlapping_ngrams(s, n) - if TelescopeCachedNgrams[s] and TelescopeCachedNgrams[s][n] then - return TelescopeCachedNgrams[s][n] + if cached_ngrams[s] and cached_ngrams[s][n] then + return cached_ngrams[s][n] end local R = {} @@ -216,15 +216,18 @@ sorters.get_fuzzy_file = function(opts) R[#R + 1] = s:sub(i, i + n - 1) end - if not TelescopeCachedNgrams[s] then - TelescopeCachedNgrams[s] = {} + if not cached_ngrams[s] then + cached_ngrams[s] = {} end - TelescopeCachedNgrams[s][n] = R + cached_ngrams[s][n] = R return R end + local cached_tails = make_cached_tail() + local cached_uppers = make_cached_uppers() + return Sorter:new { scoring_function = function(_, prompt, line) local N = #prompt @@ -243,8 +246,8 @@ sorters.get_fuzzy_file = function(opts) -- Contains the original string local contains_string = line_lower:find(prompt_lower, 1, true) - local prompt_uppers = TelescopeCachedUppers[prompt] - local line_uppers = TelescopeCachedUppers[line] + local prompt_uppers = cached_uppers[prompt] + local line_uppers = cached_uppers[line] local uppers_matching = 0 for k, _ in pairs(prompt_uppers) do @@ -254,7 +257,7 @@ sorters.get_fuzzy_file = function(opts) end -- TODO: Consider case senstivity - local tail = TelescopeCachedTails[line_lower] + local tail = cached_tails[line_lower] local contains_tail = tail:find(prompt, 1, true) local consecutive_matches = 0 @@ -313,9 +316,10 @@ sorters.get_generic_fuzzy_sorter = function(opts) local ngram_len = opts.ngram_len or 2 + local cached_ngrams = {} local function overlapping_ngrams(s, n) - if TelescopeCachedNgrams[s] and TelescopeCachedNgrams[s][n] then - return TelescopeCachedNgrams[s][n] + if cached_ngrams[s] and cached_ngrams[s][n] then + return cached_ngrams[s][n] end local R = {} @@ -323,11 +327,11 @@ sorters.get_generic_fuzzy_sorter = function(opts) R[#R + 1] = s:sub(i, i + n - 1) end - if not TelescopeCachedNgrams[s] then - TelescopeCachedNgrams[s] = {} + if not cached_ngrams[s] then + cached_ngrams[s] = {} end - TelescopeCachedNgrams[s][n] = R + cached_ngrams[s][n] = R return R end @@ -462,6 +466,9 @@ sorters.get_fzy_sorter = function(opts) } end +-- TODO: Could probably do something nice where we check their conf +-- and choose their default for this. +-- But I think `fzy` is good default for now. sorters.highlighter_only = function(opts) opts = opts or {} local fzy = opts.fzy_mod or require "telescope.algos.fzy" |
