Replies: 3 comments 14 replies
-
That is certainly an interesting idea to implement. Nice job trying to implement it! Sorry, it is a bit convoluted to review in full, but here are the steps I'd take to implement this:
That depends on the query and 'ignorecase'/'smartcase' options. If you need to compare to the data from 'mini.visits', then possibly convert that to lowercase (if 'mini.pick' uses it in that particular call). |
Beta Was this translation helpful? Give feedback.
-
Thanks! That makes sense, and would cut out a lot of the extra scoring logic in my implementation. |
Beta Was this translation helpful? Give feedback.
-
I see. Is there any way of calling default_match without sorting?
Okey, the problem was that Any way, I've done a rewrite of this. To improve consistency, I've managed to use MiniPick.registry.frecency = function()
local inf = math.huge
local visit_paths = MiniVisits.list_paths()
visit_paths = vim.tbl_map(function(path) return vim.fn.fnamemodify(path, ":.") end, visit_paths)
vim.tbl_add_reverse_lookup(visit_paths)
-- current file last
local current_file = vim.fn.expand("%:.")
if visit_paths[current_file] then
visit_paths[current_file] = inf
end
MiniPick.builtin.files(nil, {
source = {
name = "Files (MRU)",
match = function(stritems, indices, query)
local filtered = MiniPick.default_match(stritems, indices, query, true) or {}
table.sort(filtered,
function(item1, item2)
local path1 = stritems[item1]
local path2 = stritems[item2]
local score1 = visit_paths[path1] or inf -- inf for paths not visited
local score2 = visit_paths[path2] or inf -- inf for paths not visited
return score1 < score2
end
)
return filtered
end,
},
})
end I don't know how could this behave with a huge amount of files, as I'm calling |
Beta Was this translation helpful? Give feedback.
-
I wanted to write a frecency file picker which shows all files which would normally be seen in
:Pick files
, but sorted by frecency using data frommini.visits
.I'm currently using the implementation below, but it currently doesn't work with files with uppercase letters in their name, as all the paths passed in
stritems
tomatch()
seem to be lowercase. As a result, they don't match the table keys fromMiniVisits.get_index()
.What would be a good workaround for this?
Beta Was this translation helpful? Give feedback.
All reactions