mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
import from v:oldfiles on first run
This commit is contained in:
parent
5e89b52e10
commit
e547c1cd32
@ -15,11 +15,24 @@ local recency_modifier = {
|
||||
|
||||
local sql_wrapper = nil
|
||||
|
||||
local function import_oldfiles()
|
||||
local oldfiles = vim.api.nvim_get_vvar("oldfiles")
|
||||
for _, filepath in pairs(oldfiles) do
|
||||
-- TODO: don't touch existing entries
|
||||
sql_wrapper:update(filepath)
|
||||
end
|
||||
print(("Telescope-Frecency: Imported %d entries from oldfiles."):format(#oldfiles))
|
||||
end
|
||||
|
||||
local function init()
|
||||
if sql_wrapper then return end
|
||||
|
||||
sql_wrapper = sqlwrap:new()
|
||||
sql_wrapper:bootstrap()
|
||||
local first_run = sql_wrapper:bootstrap()
|
||||
if first_run then
|
||||
-- TODO: this needs to be scheduled for after shada load
|
||||
vim.defer_fn(import_oldfiles, 100)
|
||||
end
|
||||
|
||||
-- setup autocommands
|
||||
vim.api.nvim_command("augroup TelescopeFrecency")
|
||||
|
||||
@ -46,25 +46,28 @@ function M:bootstrap(opts)
|
||||
return
|
||||
end
|
||||
|
||||
local first_run = false
|
||||
if not self.db:exists("files") then
|
||||
first_run = true
|
||||
-- create tables if they don't exist
|
||||
self.db:create("files", {
|
||||
ensure = true,
|
||||
id = {"INTEGER", "PRIMARY", "KEY"},
|
||||
count = "INTEGER",
|
||||
path = "TEXT"
|
||||
})
|
||||
self.db:create("timestamps", {
|
||||
ensure = true,
|
||||
id = {"INTEGER", "PRIMARY", "KEY"},
|
||||
file_id = "INTEGER",
|
||||
timestamp = "REAL"
|
||||
-- FOREIGN KEY(file_id) REFERENCES files(id)
|
||||
})
|
||||
self.db:close()
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------
|
||||
self.db:close()
|
||||
return first_run
|
||||
end
|
||||
|
||||
--
|
||||
|
||||
function M:do_transaction(t, params)
|
||||
return self.db:with_open(function(db)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user