mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
Detect entries when it has added new ones (#87)
This commit is contained in:
parent
10771fdb7b
commit
62cbd4e7f5
@ -199,7 +199,7 @@ local frecency = function(opts)
|
|||||||
state.active_filter_tag = filter
|
state.active_filter_tag = filter
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(state.results) or filter_updated then
|
if vim.tbl_isempty(state.results) or db_client.has_updated_results() or filter_updated then
|
||||||
state.results = db_client.get_file_scores(state.show_unindexed, ws_dir)
|
state.results = db_client.get_file_scores(state.show_unindexed, ws_dir)
|
||||||
end
|
end
|
||||||
return filter_updated
|
return filter_updated
|
||||||
|
|||||||
@ -182,6 +182,8 @@ local function filter_workspace(workspace_path, show_unindexed)
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local updated = false
|
||||||
|
|
||||||
local function get_file_scores(show_unindexed, workspace_path)
|
local function get_file_scores(show_unindexed, workspace_path)
|
||||||
if not sql_wrapper then return {} end
|
if not sql_wrapper then return {} end
|
||||||
|
|
||||||
@ -205,6 +207,8 @@ local function get_file_scores(show_unindexed, workspace_path)
|
|||||||
-- sort the table
|
-- sort the table
|
||||||
table.sort(scores, function(a, b) return a.score > b.score end)
|
table.sort(scores, function(a, b) return a.score > b.score end)
|
||||||
|
|
||||||
|
updated = false
|
||||||
|
|
||||||
return scores
|
return scores
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -218,13 +222,18 @@ local function autocmd_handler(filepath)
|
|||||||
if file_is_ignored(filepath) then return end
|
if file_is_ignored(filepath) then return end
|
||||||
|
|
||||||
vim.b.telescope_frecency_registered = 1
|
vim.b.telescope_frecency_registered = 1
|
||||||
sql_wrapper:update(filepath)
|
updated = sql_wrapper:update(filepath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function has_updated_results()
|
||||||
|
return updated
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init = init,
|
init = init,
|
||||||
get_file_scores = get_file_scores,
|
get_file_scores = get_file_scores,
|
||||||
autocmd_handler = autocmd_handler,
|
autocmd_handler = autocmd_handler,
|
||||||
validate = validate_db,
|
validate = validate_db,
|
||||||
|
has_updated_results = has_updated_results,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -154,9 +154,11 @@ function M:update(filepath)
|
|||||||
-- create entry if it doesn't exist
|
-- create entry if it doesn't exist
|
||||||
local file_id
|
local file_id
|
||||||
file_id = row_id(self:do_transaction(queries.file_get_entries, {where = {path = filepath}}))
|
file_id = row_id(self:do_transaction(queries.file_get_entries, {where = {path = filepath}}))
|
||||||
|
local has_added_entry
|
||||||
if not file_id then
|
if not file_id then
|
||||||
self:do_transaction(queries.file_add_entry, {path = filepath, count = 1})
|
self:do_transaction(queries.file_add_entry, {path = filepath, count = 1})
|
||||||
file_id = row_id(self:do_transaction(queries.file_get_entries, {where = {path = filepath}}))
|
file_id = row_id(self:do_transaction(queries.file_get_entries, {where = {path = filepath}}))
|
||||||
|
has_added_entry = true
|
||||||
else
|
else
|
||||||
-- ..or update existing entry
|
-- ..or update existing entry
|
||||||
self:do_transaction(queries.file_update_counter, {path = filepath})
|
self:do_transaction(queries.file_update_counter, {path = filepath})
|
||||||
@ -171,6 +173,8 @@ function M:update(filepath)
|
|||||||
if trim_at then
|
if trim_at then
|
||||||
self:do_transaction(queries.timestamp_delete_before_id, {id = trim_at.id, file_id = file_id})
|
self:do_transaction(queries.timestamp_delete_before_id, {id = trim_at.id, file_id = file_id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return has_added_entry
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user