fix(telescope): handle file listing in non-Git repositories
This commit is contained in:
parent
5b83c48fce
commit
0d48b8f8e5
@ -136,7 +136,7 @@ function FileSelector:fzf_ui(handler)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local close_action = function() handler(nil) end
|
local close_action = function() handler(nil) end
|
||||||
fzf_lua.files(vim.tbl_deep_extend("force", Config.file_selector.provider_opts, {
|
fzf_lua.files(vim.tbl_deep_extend("force", {
|
||||||
file_ignore_patterns = self.selected_filepaths,
|
file_ignore_patterns = self.selected_filepaths,
|
||||||
prompt = string.format("%s> ", PROMPT_TITLE),
|
prompt = string.format("%s> ", PROMPT_TITLE),
|
||||||
fzf_opts = {},
|
fzf_opts = {},
|
||||||
@ -156,7 +156,7 @@ function FileSelector:fzf_ui(handler)
|
|||||||
["esc"] = close_action,
|
["esc"] = close_action,
|
||||||
["ctrl-c"] = close_action,
|
["ctrl-c"] = close_action,
|
||||||
},
|
},
|
||||||
}))
|
}, Config.file_selector.provider_opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
function FileSelector:mini_pick_ui(handler)
|
function FileSelector:mini_pick_ui(handler)
|
||||||
@ -194,13 +194,17 @@ function FileSelector:telescope_ui(handler)
|
|||||||
local action_state = require("telescope.actions.state")
|
local action_state = require("telescope.actions.state")
|
||||||
local action_utils = require("telescope.actions.utils")
|
local action_utils = require("telescope.actions.utils")
|
||||||
|
|
||||||
|
local project_root = Utils.get_project_root()
|
||||||
|
local files = Utils.scan_directory_respect_gitignore(project_root)
|
||||||
|
files = vim.iter(files):map(function(filepath) return Path:new(filepath):make_relative(project_root) end):totable()
|
||||||
|
|
||||||
pickers
|
pickers
|
||||||
.new(
|
.new(
|
||||||
{},
|
{},
|
||||||
vim.tbl_extend("force", Config.file_selector.provider_opts, {
|
vim.tbl_extend("force", {
|
||||||
file_ignore_patterns = self.selected_filepaths,
|
file_ignore_patterns = self.selected_filepaths,
|
||||||
prompt_title = string.format("%s> ", PROMPT_TITLE),
|
prompt_title = string.format("%s> ", PROMPT_TITLE),
|
||||||
finder = finders.new_oneshot_job({ "git", "ls-files" }, { cwd = Utils.get_project_root() }),
|
finder = finders.new_table(files),
|
||||||
sorter = conf.file_sorter(),
|
sorter = conf.file_sorter(),
|
||||||
attach_mappings = function(prompt_bufnr, map)
|
attach_mappings = function(prompt_bufnr, map)
|
||||||
map("i", "<esc>", require("telescope.actions").close)
|
map("i", "<esc>", require("telescope.actions").close)
|
||||||
@ -224,7 +228,7 @@ function FileSelector:telescope_ui(handler)
|
|||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
}, Config.file_selector.provider_opts)
|
||||||
)
|
)
|
||||||
:find()
|
:find()
|
||||||
end
|
end
|
||||||
|
@ -643,6 +643,13 @@ function M.is_ignored(file, ignore_patterns, negate_patterns)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.scan_directory_respect_gitignore(directory)
|
||||||
|
local gitignore_path = directory .. "/.gitignore"
|
||||||
|
local gitignore_patterns, gitignore_negate_patterns = M.parse_gitignore(gitignore_path)
|
||||||
|
gitignore_patterns = vim.list_extend(gitignore_patterns, { "%.git", "%.worktree", "__pycache__", "node_modules" })
|
||||||
|
return M.scan_directory(directory, gitignore_patterns, gitignore_negate_patterns)
|
||||||
|
end
|
||||||
|
|
||||||
function M.scan_directory(directory, ignore_patterns, negate_patterns)
|
function M.scan_directory(directory, ignore_patterns, negate_patterns)
|
||||||
local files = {}
|
local files = {}
|
||||||
local handle = vim.loop.fs_scandir(directory)
|
local handle = vim.loop.fs_scandir(directory)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user