mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
refactor: make joinpath more simple (#121)
This commit is contained in:
parent
1acb245b01
commit
9b17c17744
@ -36,12 +36,12 @@ AsyncFinder.new = function(fs, path, entry_maker, initial_results)
|
|||||||
if self.closed then
|
if self.closed then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
local fullpath = fs:joinpath(path, name)
|
local fullpath = fs.joinpath(path, name)
|
||||||
if not seen[fullpath] then
|
if not seen[fullpath] then
|
||||||
seen[fullpath] = true
|
seen[fullpath] = true
|
||||||
index = index + 1
|
index = index + 1
|
||||||
count = count + 1
|
count = count + 1
|
||||||
local entry = entry_maker { id = 0, count = 0, path = fs:joinpath(path, name), score = 0 }
|
local entry = entry_maker { id = 0, count = 0, path = fs.joinpath(path, name), score = 0 }
|
||||||
if entry then
|
if entry then
|
||||||
entry.index = index
|
entry.index = index
|
||||||
table.insert(self.entries, entry)
|
table.insert(self.entries, entry)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ local uv = vim.uv or vim.loop
|
|||||||
|
|
||||||
---@class FrecencyFS
|
---@class FrecencyFS
|
||||||
---@field os_homedir string
|
---@field os_homedir string
|
||||||
|
---@field joinpath fun(...: string): string
|
||||||
---@field private config FrecencyFSConfig
|
---@field private config FrecencyFSConfig
|
||||||
---@field private ignore_regexes string[]
|
---@field private ignore_regexes string[]
|
||||||
local FS = {}
|
local FS = {}
|
||||||
@ -26,20 +27,11 @@ FS.new = function(config)
|
|||||||
local regex = escaped:gsub("%%%*", ".*"):gsub("%%%?", ".")
|
local regex = escaped:gsub("%%%*", ".*"):gsub("%%%?", ".")
|
||||||
return "^" .. regex .. "$"
|
return "^" .. regex .. "$"
|
||||||
end, self.config.ignore_patterns)
|
end, self.config.ignore_patterns)
|
||||||
return self
|
---This is needed for Neovim v0.9.0.
|
||||||
end
|
self.joinpath = vim.fs.joinpath or function(...)
|
||||||
|
|
||||||
---This is needed for Neovim v0.9.0.
|
|
||||||
---@param ... string
|
|
||||||
---@return string
|
|
||||||
function FS:joinpath(...)
|
|
||||||
if vim.fs.joinpath then
|
|
||||||
return vim.fs.joinpath(...)
|
|
||||||
end
|
|
||||||
local function join_paths(...)
|
|
||||||
return (table.concat({ ... }, "/"):gsub("//+", "/"))
|
return (table.concat({ ... }, "/"):gsub("//+", "/"))
|
||||||
end
|
end
|
||||||
return join_paths(...)
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
@ -58,13 +50,13 @@ function FS:scan_dir(path)
|
|||||||
vim.fs.dir(path, {
|
vim.fs.dir(path, {
|
||||||
depth = self.config.scan_depth,
|
depth = self.config.scan_depth,
|
||||||
skip = function(dirname)
|
skip = function(dirname)
|
||||||
if self:is_ignored(self:joinpath(path, dirname)) then
|
if self:is_ignored(self.joinpath(path, dirname)) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
do
|
do
|
||||||
local fullpath = self:joinpath(path, name)
|
local fullpath = self.joinpath(path, name)
|
||||||
if type == "file" and not self:is_ignored(fullpath) and gitignore({ path }, fullpath) then
|
if type == "file" and not self:is_ignored(fullpath) and gitignore({ path }, fullpath) then
|
||||||
coroutine.yield(name)
|
coroutine.yield(name)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user