import from v:oldfiles on first run

This commit is contained in:
Senghan Bright 2021-01-16 18:47:17 +01:00
parent 5e89b52e10
commit e547c1cd32
2 changed files with 33 additions and 17 deletions

View File

@ -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")

View File

@ -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)