Add 'ignore_missing_dirs' option to not show warnings when a directory is missing

This commit is contained in:
2025-02-14 23:20:06 -05:00
parent 1d7920e799
commit 08ad7b207f
3 changed files with 9 additions and 4 deletions

View File

@@ -122,6 +122,7 @@ lua require'telescope'.extensions.project.project{ display_type = 'full' }
| Keys | Description | Options | | Keys | Description | Options |
|-----------------------|------------------------------------------------|------------------------------------------------------| |-----------------------|------------------------------------------------|------------------------------------------------------|
| `base_dirs` | Array of project base directory configurations | table (default: nil) | | `base_dirs` | Array of project base directory configurations | table (default: nil) |
| `ignore_missing_dirs` | Don't show an error if base dirs are missing | bool (default: false) |
| `hidden_files` | Show hidden files in selected project | bool (default: false) | | `hidden_files` | Show hidden files in selected project | bool (default: false) |
| `order_by` | Order projects by `asc`, `desc`, `recent` | string (default: recent) | | `order_by` | Order projects by `asc`, `desc`, `recent` | string (default: recent) |
| `sync_with_nvim_tree` | Sync projects with nvim tree plugin | bool (default: false) | | `sync_with_nvim_tree` | Sync projects with nvim tree plugin | bool (default: false) |
@@ -143,6 +144,7 @@ require('telescope').setup {
{path = '~/dev/src4'}, {path = '~/dev/src4'},
{path = '~/dev/src5', max_depth = 2}, {path = '~/dev/src5', max_depth = 2},
}, },
ignore_missing_dirs = true, -- default: false
hidden_files = true, -- default: false hidden_files = true, -- default: false
theme = "dropdown", theme = "dropdown",
order_by = "asc", order_by = "asc",

View File

@@ -6,21 +6,22 @@ local scan = require("plenary.scandir")
local M = {} local M = {}
-- Find and store git repos if base_dirs provided -- Find and store git repos if base_dirs provided
M.update_git_repos = function(base_dirs) M.update_git_repos = function(base_dirs, ignore_missing_dirs)
if base_dirs then if base_dirs then
local normalized_config = _utils.normalize_base_dir_configs(base_dirs) local normalized_config = _utils.normalize_base_dir_configs(base_dirs)
local repo_paths = M.search_for_git_repos(normalized_config) local repo_paths = M.search_for_git_repos(normalized_config, ignore_missing_dirs)
local git_projects = M.parse_git_repo_paths(repo_paths) local git_projects = M.parse_git_repo_paths(repo_paths)
M.save_git_repos(git_projects) M.save_git_repos(git_projects)
end end
end end
-- Recurses directories under base directories to find all git projects -- Recurses directories under base directories to find all git projects
M.search_for_git_repos = function(base_dirs) M.search_for_git_repos = function(base_dirs, ignore_missing_dirs)
return iter.iter(base_dirs) return iter.iter(base_dirs)
:map(function(base_dir) :map(function(base_dir)
local git_dirs = scan.scan_dir(vim.fn.expand(base_dir.path), { local git_dirs = scan.scan_dir(vim.fn.expand(base_dir.path), {
depth = base_dir.max_depth, depth = base_dir.max_depth,
silent = ignore_missing_dirs,
add_dirs = true, add_dirs = true,
hidden = true, hidden = true,
search_pattern = "%.git$" search_pattern = "%.git$"

View File

@@ -15,6 +15,7 @@ local M = {}
-- Variables that setup can change -- Variables that setup can change
local base_dirs local base_dirs
local ignore_missing_dirs
local hidden_files local hidden_files
local order_by local order_by
local on_project_selected local on_project_selected
@@ -59,6 +60,7 @@ M.setup = function(setup_config)
end end
base_dirs = setup_config.base_dirs or nil base_dirs = setup_config.base_dirs or nil
ignore_missing_dirs = setup_config.ignore_missing_dirs or false
hidden_files = setup_config.hidden_files or false hidden_files = setup_config.hidden_files or false
order_by = setup_config.order_by or "recent" order_by = setup_config.order_by or "recent"
on_project_selected = setup_config.on_project_selected on_project_selected = setup_config.on_project_selected
@@ -66,7 +68,7 @@ M.setup = function(setup_config)
sync_with_nvim_tree = setup_config.sync_with_nvim_tree or false sync_with_nvim_tree = setup_config.sync_with_nvim_tree or false
local cd_scope = setup_config.cd_scope or { "tab", "window" } local cd_scope = setup_config.cd_scope or { "tab", "window" }
_actions.set_cd_scope(cd_scope) _actions.set_cd_scope(cd_scope)
_git.update_git_repos(base_dirs) _git.update_git_repos(base_dirs, ignore_missing_dirs)
local config_maps = setup_config.mappings or {} local config_maps = setup_config.mappings or {}
for mode, maps in pairs(config_maps) do for mode, maps in pairs(config_maps) do