summaryrefslogtreecommitdiff
path: root/lua/telescope/sorters.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-07-17 00:03:20 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-07-17 00:03:20 -0400
commitababfbfd88334ca6d94d5d0a8b6324dd6600d602 (patch)
tree99dd820cca2d906175b9a645694cb778add58499 /lua/telescope/sorters.lua
parentc6f0142fc651dcbd2431630956d034c046293e7e (diff)
Another stream
Diffstat (limited to 'lua/telescope/sorters.lua')
-rw-r--r--lua/telescope/sorters.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/lua/telescope/sorters.lua b/lua/telescope/sorters.lua
new file mode 100644
index 0000000..d5fb6f9
--- /dev/null
+++ b/lua/telescope/sorters.lua
@@ -0,0 +1,32 @@
+local sorters = {}
+
+
+local Sorter = {}
+Sorter.__index = Sorter
+
+---@class Sorter
+--- Sorter sorts a list of results by return a single integer for a line,
+--- given a prompt
+---
+--- Lower number is better (because it's like a closer match)
+--- But, any number below 0 means you want that line filtered out.
+--- @param scoring_function function Function that has the interface:
+-- (sorter, prompt, line): number
+function Sorter:new(opts)
+ opts = opts or {}
+
+ return setmetatable({
+ state = {},
+ scoring_function = opts.scoring_function,
+ }, Sorter)
+end
+
+function Sorter:score(prompt, line)
+ return self:scoring_function(prompt, line)
+end
+
+function sorters.new(...)
+ return Sorter:new(...)
+end
+
+return sorters