telescope-frecency.nvim
telescope-frecency.nvim copied to clipboard
Use frecency with git_files
Hi,
I would like to use this with git_files or ideally with https://github.com/nvim-telescope/telescope.nvim/wiki/Configuration-Recipes#falling-back-to-find_files-if-git_files-cant-find-a-git-directory
Is there any way to do this? I think #13 and #4 are going this way of being able to use frecency with any picker, not just recent files, but the current workaround with the workspaces is not it.
Anyway, thanks for the great work!
the current workaround with the workspaces is not it
Is it really a workaround if this feature was planed like for the beginning :thinking:
git_files isnt that easy to integrate here, because we arnt shelling out to get the workspace files. We use plenary.scandir which uses uv.fs_scandir
Hi,
as far as I understand the architecture of telescope (which is not that much I have to admit), the fundamental issue for this as well as the other mentioned issues is that frecency is a picker and not a sorter - if it were a sorter, it could work on find_files, git_files and any other files-based picker. But because it's a picker, it has to replicate the functionality of all these pickers if it is to be able to do that.
Am I correct?
A sorter is nothing more than a function that gets a entry and the current prompt and returns a score.
You maybe can get a list, from find_files and ask sql for the score of the file. That way you could do a initial sorting. And if the prompt is not empty call a real fuzzy sorter?
But you still need a simple list all my frecency entries because the sorter cant add new things to a picker.
PR welcome
I thought about it a little bit more. I havent this project, just havent seen the creator in months.
I think this might actually work. A additional frecency sorter you can set on top of find_files and git_files which might be a alternative to the tags idea. But i dont think the frecency picker itself will go away because sometimes you still need a look outside of your cwd.
Yes, that is what I was thinking - a frecency sorter set on top of find_files or git_files which wouldn't add entries, just sort them based on their frecency... There is obviously a lot of things to think through like what to do with files which are not in the database, whether frecency should kick in with a non-empty prompt (honestly, why not?) etc.
I do think that this picker would be obsoleted by that - you could just use the frecency sorter with the builtin.oldfiles picker instead to achieve the same effect, right?
Hey there! I'm seeing the exact same issue with this project: It's a picker, rather than a sorter.
This would also make sense for :Telescope buffers, to pre-select the most frecent buffer.
Are there any news on this issue?
I think the news are that it will happen if there's someone willing to make it...
This is what I am using
local ext = require("telescope._extensions")
local builtins = require("telescope.builtin")
local frecency_db = require("telescope._extensions.frecency.db_client")
local fzf = ext.manager.fzf
local function frecency_score(self, prompt, line, entry)
if prompt == nil or prompt == "" then
for _, file_entry in ipairs(self.state.frecency) do
local filepath = entry.cwd .. "/" .. entry.value
if file_entry.filename == filepath then
return 9999 - file_entry.score
end
end
return 9999
end
return self.default_scoring_function(self, prompt, line, entry)
end
local function frecency_start(self, prompt)
self.default_start(self, prompt)
if not self.state.frecency then
self.state.frecency = frecency_db.get_file_scores()
end
end
local frecency_sorter = function(opts)
local fzf_sorter = fzf.native_fzf_sorter()
fzf_sorter.default_scoring_function = fzf_sorter.scoring_function
fzf_sorter.default_start = fzf_sorter.start
fzf_sorter.scoring_function = frecency_score
fzf_sorter.start = frecency_start
return fzf_sorter
end
return {
frecency_sorter = frecency_sorter,
}
---
telescope.setup({
defaults = {
file_sorter = mysorter.frecency_sorter,
},
I was about to ask the same thing, I would love to use this not only for files, but also for commands
nvim-telescope/telescope.nvim/wiki/Configuration-Recipes#falling-back-to-find_files-if-git_files-cant-find-a-git-directory
local frecency_db = require("telescope._extensions.frecency.db_client")
Is outdated, there are new way to handle this?
db_client.lua is removed by #93. So I think a similar method for getting entries from frecency is below.
self.state.frecency = require("frecency").frecency().picker:fetch_results()
(I have not tried @nikhilkalige's snippets with this change.)
should such sorter be added to telescope.defaults.file_sorter?
I used to have it under telescope.extensions.frecency.sorter but nvim is complaining about a nil sorter entry
¯\_(ツ)_/¯