feat(recency_values): customize recency_values (#190)

Co-authored-by: zhaogang <zhaogang@dustess.com>
This commit is contained in:
Mr.Z 2024-04-06 19:49:45 +08:00 committed by GitHub
parent 2a22815b09
commit 08a28ec511
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 8 deletions

View File

@ -172,6 +172,20 @@ least, it matches against exact the same as you input.
See [default configuration](https://github.com/nvim-telescope/telescope.nvim#telescope-defaults) for full details on configuring Telescope. See [default configuration](https://github.com/nvim-telescope/telescope.nvim#telescope-defaults) for full details on configuring Telescope.
- `recency_values` (default: see follow)
```lua
-- recency_values default:
recency_values = {
{ age = 240, value = 100 }, -- past 4 hours
{ age = 1440, value = 80 }, -- past day
{ age = 4320, value = 60 }, -- past 3 days
{ age = 10080, value = 40 }, -- past week
{ age = 43200, value = 20 }, -- past month
{ age = 129600, value = 10 }, -- past 90 days
}
```
- `auto_validate` (default: `true`) - `auto_validate` (default: `true`)
If `true`, it removes stale entries count over than `db_validate_threshold`. See If `true`, it removes stale entries count over than `db_validate_threshold`. See

View File

@ -5,6 +5,7 @@ local os_util = require "frecency.os_util"
local Config = {} local Config = {}
---@class FrecencyRawConfig ---@class FrecencyRawConfig
---@field recency_values table<integer, { age: integer, value: integer }> default: {}
---@field auto_validate boolean default: true ---@field auto_validate boolean default: true
---@field db_root string default: vim.fn.stdpath "data" ---@field db_root string default: vim.fn.stdpath "data"
---@field db_safe_mode boolean default: true ---@field db_safe_mode boolean default: true
@ -24,6 +25,14 @@ local Config = {}
---@return FrecencyConfig ---@return FrecencyConfig
Config.new = function() Config.new = function()
local default_values = { local default_values = {
recency_values = {
{ age = 240, value = 100 }, -- past 4 hours
{ age = 1440, value = 80 }, -- past day
{ age = 4320, value = 60 }, -- past 3 days
{ age = 10080, value = 40 }, -- past week
{ age = 43200, value = 20 }, -- past month
{ age = 129600, value = 10 }, -- past 90 days
},
auto_validate = true, auto_validate = true,
db_root = vim.fn.stdpath "data", db_root = vim.fn.stdpath "data",
db_safe_mode = true, db_safe_mode = true,
@ -43,6 +52,7 @@ Config.new = function()
} }
---@type table<string, boolean> ---@type table<string, boolean>
local keys = { local keys = {
recency_values = true,
auto_validate = true, auto_validate = true,
db_root = true, db_root = true,
db_safe_mode = true, db_safe_mode = true,
@ -85,6 +95,7 @@ end
Config.setup = function(ext_config) Config.setup = function(ext_config)
local opts = vim.tbl_extend("force", config.values, ext_config or {}) local opts = vim.tbl_extend("force", config.values, ext_config or {})
vim.validate { vim.validate {
recency_values = { opts.recency_values, "t" },
auto_validate = { opts.auto_validate, "b" }, auto_validate = { opts.auto_validate, "b" },
db_root = { opts.db_root, "s" }, db_root = { opts.db_root, "s" },
db_safe_mode = { opts.db_safe_mode, "b" }, db_safe_mode = { opts.db_safe_mode, "b" },

View File

@ -7,14 +7,7 @@ local Recency = {}
---@return FrecencyRecency ---@return FrecencyRecency
Recency.new = function() Recency.new = function()
return setmetatable({ return setmetatable({
modifier = { modifier = config.recency_values,
{ age = 240, value = 100 }, -- past 4 hours
{ age = 1440, value = 80 }, -- past day
{ age = 4320, value = 60 }, -- past 3 days
{ age = 10080, value = 40 }, -- past week
{ age = 43200, value = 20 }, -- past month
{ age = 129600, value = 10 }, -- past 90 days
},
}, { __index = Recency }) }, { __index = Recency })
end end