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 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()
|
local function init()
|
||||||
if sql_wrapper then return end
|
if sql_wrapper then return end
|
||||||
|
|
||||||
sql_wrapper = sqlwrap:new()
|
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
|
-- setup autocommands
|
||||||
vim.api.nvim_command("augroup TelescopeFrecency")
|
vim.api.nvim_command("augroup TelescopeFrecency")
|
||||||
|
|||||||
@ -46,25 +46,28 @@ function M:bootstrap(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create tables if they don't exist
|
local first_run = false
|
||||||
self.db:create("files", {
|
if not self.db:exists("files") then
|
||||||
ensure = true,
|
first_run = true
|
||||||
id = {"INTEGER", "PRIMARY", "KEY"},
|
-- create tables if they don't exist
|
||||||
count = "INTEGER",
|
self.db:create("files", {
|
||||||
path = "TEXT"
|
id = {"INTEGER", "PRIMARY", "KEY"},
|
||||||
})
|
count = "INTEGER",
|
||||||
self.db:create("timestamps", {
|
path = "TEXT"
|
||||||
ensure = true,
|
})
|
||||||
id = {"INTEGER", "PRIMARY", "KEY"},
|
self.db:create("timestamps", {
|
||||||
file_id = "INTEGER",
|
id = {"INTEGER", "PRIMARY", "KEY"},
|
||||||
timestamp = "REAL"
|
file_id = "INTEGER",
|
||||||
-- FOREIGN KEY(file_id) REFERENCES files(id)
|
timestamp = "REAL"
|
||||||
})
|
-- FOREIGN KEY(file_id) REFERENCES files(id)
|
||||||
self.db:close()
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
self.db:close()
|
||||||
|
return first_run
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------
|
--
|
||||||
|
|
||||||
function M:do_transaction(t, params)
|
function M:do_transaction(t, params)
|
||||||
return self.db:with_open(function(db)
|
return self.db:with_open(function(db)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user