mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
* refactor: make logic for Database be abstract * feat: add logic for DB by string.dump * fix: run with async.void to run synchronously * test: add tests for native feature * feat!: sort candidates by path when score is same This is needed because candidates from SQLite is sorted by id, but ones from native is sorted by path. * chore: clean up types * feat: add lock/unlock feature to access DB * test: use async version of busted And disable benchmark tests (fix later) * test: add tests for file_lock * chore: use more explicit names * chore: use plenary.log instead * fix: wait async functions definitely * feat: add migrator * chore: fix logging * fix: detect emptiness of the table * fix: deal with buffer with no names * test: loosen the condition temporarily * test: add tests for migrator * fix: return true when the table is not empty * feat: load sqlite lazily not to require in start * chore: add logging to calculate time for fetching * feat: add converter from native code to SQLite * feat: warn when sqlite.lua is not available * feat: add FrecencyMigrateDB to migrate DB * docs: add note for native code logic * test: ignore type bug
55 lines
1.2 KiB
Lua
55 lines
1.2 KiB
Lua
local async = require "plenary.async"
|
|
|
|
---@class FrecencyWait
|
|
---@field config FrecencyWaitConfig
|
|
local Wait = {}
|
|
|
|
---@class FrecencyWaitConfig
|
|
---@field time integer default: 5000
|
|
---@field interval integer default: 200
|
|
|
|
---@alias FrecencyWaitCallback fun(): nil
|
|
|
|
---@param f FrecencyWaitCallback
|
|
---@param opts FrecencyWaitConfig?
|
|
Wait.new = function(f, opts)
|
|
return setmetatable(
|
|
{ f = f, config = vim.tbl_extend("force", { time = 5000, interval = 200 }, opts or {}) },
|
|
{ __index = Wait }
|
|
)
|
|
end
|
|
|
|
---@async
|
|
---@private
|
|
Wait.f = function()
|
|
error "implement me"
|
|
end
|
|
|
|
---@return boolean ok
|
|
---@return nil|-1|-2 status
|
|
function Wait:run()
|
|
local done = false
|
|
async.void(function()
|
|
self.f()
|
|
done = true
|
|
end)()
|
|
return vim.wait(self.config.time, function()
|
|
return done
|
|
end, self.config.interval)
|
|
end
|
|
|
|
---@param f FrecencyWaitCallback
|
|
---@param opts FrecencyWaitConfig?
|
|
---@return nil
|
|
return function(f, opts)
|
|
local wait = Wait.new(f, opts)
|
|
local ok, status = wait:run()
|
|
if ok then
|
|
return
|
|
elseif status == -1 then
|
|
error "callback never returnes during the time"
|
|
elseif status == -2 then
|
|
error "callback is interrupted during the time"
|
|
end
|
|
end
|