Skip to content

Commit

Permalink
feat: add an option to select matcher logic
Browse files Browse the repository at this point in the history
  • Loading branch information
delphinus committed Apr 16, 2024
1 parent de477db commit 943c506
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lua/frecency/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local Config = {}
---@field filter_delimiter string default: ":"
---@field hide_current_buffer boolean default: false
---@field ignore_patterns string[] default: { "*.git/*", "*/tmp/*", "term://*" }
---@field matcher "default"|"fuzzy" default: "default"
---@field max_timestamps integer default: 10
---@field show_filter_column boolean|string[] default: true
---@field show_scores boolean default: false
Expand All @@ -35,6 +36,7 @@ Config.new = function()
hide_current_buffer = false,
ignore_patterns = os_util.is_windows and { [[*.git\*]], [[*\tmp\*]], "term://*" }
or { "*.git/*", "*/tmp/*", "term://*" },
matcher = "default",
max_timestamps = 10,
recency_values = {
{ age = 240, value = 100 }, -- past 4 hours
Expand Down Expand Up @@ -62,6 +64,7 @@ Config.new = function()
filter_delimiter = true,
hide_current_buffer = true,
ignore_patterns = true,
matcher = true,
max_timestamps = true,
show_filter_column = true,
show_scores = true,
Expand Down Expand Up @@ -105,6 +108,13 @@ Config.setup = function(ext_config)
filter_delimiter = { opts.filter_delimiter, "s" },
hide_current_buffer = { opts.hide_current_buffer, "b" },
ignore_patterns = { opts.ignore_patterns, "t" },
matcher = {
opts.matcher,
function(v)
return type(v) == "string" and (v == "default" or v == "fuzzy")
end,
'"default" or "fuzzy"',
},
max_timestamps = {
opts.max_timestamps,
function(v)
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion lua/frecency/picker.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local State = require "frecency.state"
local Finder = require "frecency.finder"
local config = require "frecency.config"
local fuzzy_sorter = require "frecency.fuzzy_sorter"
local sorters = require "telescope.sorters"
local log = require "plenary.log"
local Path = require "plenary.path" --[[@as FrecencyPlenaryPath]]
Expand Down Expand Up @@ -105,7 +106,7 @@ function Picker:start(opts)
prompt_title = "Frecency",
finder = finder,
previewer = config_values.file_previewer(opts),
sorter = require "frecency.sorter",
sorter = config.matcher == "default" and sorters.get_substr_matcher() or fuzzy_sorter,
on_input_filter_cb = self:on_input_filter_cb(opts),
attach_mappings = function(prompt_bufnr)
return self:attach_mappings(prompt_bufnr)
Expand Down

0 comments on commit 943c506

Please sign in to comment.