mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
improve substr matcher
This commit is contained in:
parent
0e606ebfca
commit
dc37ed8dd0
@ -9,6 +9,7 @@ end
|
|||||||
local db_client = require("telescope._extensions.frecency.db_client")
|
local db_client = require("telescope._extensions.frecency.db_client")
|
||||||
-- vim.defer_fn(db_client.init, 100) -- TODO: this is a crappy attempt to lessen loadtime impact, use VimEnter?
|
-- vim.defer_fn(db_client.init, 100) -- TODO: this is a crappy attempt to lessen loadtime impact, use VimEnter?
|
||||||
db_client.init()
|
db_client.init()
|
||||||
|
local os_path_sep = vim.loop.os_uname().sysname == "Windows" and "\\" or "/"
|
||||||
|
|
||||||
|
|
||||||
-- finder code
|
-- finder code
|
||||||
@ -32,8 +33,6 @@ local frecency = function(opts)
|
|||||||
-- TODO: decide on how to handle cwd or lsp_workspace for pathname shorten?
|
-- TODO: decide on how to handle cwd or lsp_workspace for pathname shorten?
|
||||||
local results = db_client.get_file_scores(opts) -- TODO: pass `filter_workspace` option
|
local results = db_client.get_file_scores(opts) -- TODO: pass `filter_workspace` option
|
||||||
|
|
||||||
local os_path_sep = vim.loop.os_uname().sysname == "Windows" and "\\" or "/"
|
|
||||||
|
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
separator = "",
|
separator = "",
|
||||||
hl_chars = {[os_path_sep] = "TelescopePathSeparator"},
|
hl_chars = {[os_path_sep] = "TelescopePathSeparator"},
|
||||||
@ -49,7 +48,6 @@ local frecency = function(opts)
|
|||||||
local buf_is_loaded = vim.api.nvim_buf_is_loaded
|
local buf_is_loaded = vim.api.nvim_buf_is_loaded
|
||||||
|
|
||||||
local filename = entry.name
|
local filename = entry.name
|
||||||
|
|
||||||
local hl_filename = buf_is_loaded(bufnr(filename)) and "TelescopeBufferLoaded" or ""
|
local hl_filename = buf_is_loaded(bufnr(filename)) and "TelescopeBufferLoaded" or ""
|
||||||
|
|
||||||
if opts.tail_path then
|
if opts.tail_path then
|
||||||
@ -60,8 +58,6 @@ local frecency = function(opts)
|
|||||||
|
|
||||||
filename = path.make_relative(filename, cwd)
|
filename = path.make_relative(filename, cwd)
|
||||||
|
|
||||||
|
|
||||||
-- TODO: remove score from display; only there for debug
|
|
||||||
return displayer {
|
return displayer {
|
||||||
{entry.score, "Directory"},
|
{entry.score, "Directory"},
|
||||||
{filename, hl_filename},
|
{filename, hl_filename},
|
||||||
|
|||||||
@ -36,20 +36,17 @@ my_sorters.get_substr_matcher = function(opts)
|
|||||||
substr.scoring_function = function(_, prompt, _, entry)
|
substr.scoring_function = function(_, prompt, _, entry)
|
||||||
local display = entry.name:lower()
|
local display = entry.name:lower()
|
||||||
|
|
||||||
local search_terms = util.split(prompt, " ")
|
local search_terms = util.split(prompt, "%s")
|
||||||
local matched
|
local matched = 0
|
||||||
|
local total_search_terms = 0
|
||||||
for _, word in pairs(search_terms) do
|
for _, word in pairs(search_terms) do
|
||||||
matched = display:find(word, 1, true) and 1 or -1
|
total_search_terms = total_search_terms + 1
|
||||||
if matched == -1 then goto continue end
|
if display:find(word, 1, true) then
|
||||||
|
matched = matched + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::continue::
|
return matched == total_search_terms and entry.index or -1
|
||||||
|
|
||||||
if matched == -1 then
|
|
||||||
return -1
|
|
||||||
else
|
|
||||||
return entry.index
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return substr
|
return substr
|
||||||
|
|||||||
@ -34,7 +34,7 @@ end
|
|||||||
|
|
||||||
util.split = function(str, delimiter)
|
util.split = function(str, delimiter)
|
||||||
local result = {}
|
local result = {}
|
||||||
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
|
for match in str:gmatch("[^" .. delimiter .. "]+") do
|
||||||
table.insert(result, match)
|
table.insert(result, match)
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user