diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2021-04-08 10:35:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-08 10:35:44 -0400 |
| commit | 64e59060b1750d0c86761693b6847c3db07afcd2 (patch) | |
| tree | 13e8c0117cdff926e7bbf107f5496c733329cfb7 /lua/telescope/sorters.lua | |
| parent | e5fbe6fe60149af8fdeef0d07cba06c029258ba0 (diff) | |
feat: asyncify pickers - except for live_grep (#709)
* something kind of works already
* yayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayaya
* use async for everything besides live jobs
* fix: fixup autocmds previewer
* fix: lints for prime
* temp: Add example of how we can think about async sorters
* feat: Allow picker to decide when to cancel
* fix: simplify scoring logic and tests
* fixup: name
* fix: Move back towards more backwards compat methods
* fixup: Remove results from opts
* fixup: remove trailing quote
* fixup: Attempt to clean up some more async items. Next is status
* wip: Add todo for when bfredl implements extmarks over the EOL
* wip
* fixup: got em
* fixup: cleaning
* fixup: docs
Diffstat (limited to 'lua/telescope/sorters.lua')
| -rw-r--r-- | lua/telescope/sorters.lua | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lua/telescope/sorters.lua b/lua/telescope/sorters.lua index 5ac7086..4147f59 100644 --- a/lua/telescope/sorters.lua +++ b/lua/telescope/sorters.lua @@ -32,12 +32,17 @@ Sorter.__index = Sorter --- --- Lower number is better (because it's like a closer match) --- But, any number below 0 means you want that line filtered out. ---- @field scoring_function function Function that has the interface: --- (sorter, prompt, line): number +---@field scoring_function function: Function that has the interface: (sorter, prompt, line): number +---@field tags table: Unique tags collected at filtering for tag completion +---@field filter_function function: Function that can filter results +---@field highlighter function: Highlights results to display them pretty +---@field discard boolean: Whether this is a discardable style sorter or not. +---@field score function: Override the score function if desired. function Sorter:new(opts) opts = opts or {} return setmetatable({ + score = opts.score, state = {}, tags = opts.tags, filter_function = opts.filter_function, @@ -77,13 +82,12 @@ end -- TODO: Consider doing something that makes it so we can skip the filter checks -- if we're not discarding. Also, that means we don't have to check otherwise as well :) -function Sorter:score(prompt, entry) - if not entry or not entry.ordinal then return -1 end +function Sorter:score(prompt, entry, cb_add, cb_filter) + if not entry or not entry.ordinal then return end local ordinal = entry.ordinal - if self:_was_discarded(prompt, ordinal) then - return FILTERED + return cb_filter(entry) end local filter_score @@ -92,14 +96,21 @@ function Sorter:score(prompt, entry) filter_score, prompt = self:filter_function(prompt, entry) end - local score = (filter_score == FILTERED and FILTERED or - self:scoring_function(prompt or "", ordinal, entry)) + if filter_score == FILTERED then + return cb_filter(entry) + end + local score = self:scoring_function(prompt or "", ordinal, entry) if score == FILTERED then self:_mark_discarded(prompt, ordinal) + return cb_filter(entry) end - return score + if cb_add then + return cb_add(score, entry) + else + return score + end end function Sorter:_was_discarded(prompt, ordinal) |
