feat(maestro): exclude hidden dirs from spawn-form autocomplete (NAP-329)
ci / rust (push) Successful in 5m6s
ci / rust (push) Successful in 5m6s
This commit is contained in:
@@ -28,7 +28,7 @@ pub const MAX_ENTRIES: usize = 1000;
|
||||
|
||||
/// List the immediate subdirectories of `requested`, expanding it against
|
||||
/// `home_dir` first. Returns directory **names** only (not full paths), sorted
|
||||
/// case-insensitively, with hidden entries included.
|
||||
/// case-insensitively. Hidden directories (dotfiles) are excluded.
|
||||
pub fn list_dir(home_dir: &str, requested: &str) -> Result<DirListing, ErrorInfo> {
|
||||
let dir = resolve(home_dir, requested);
|
||||
|
||||
@@ -36,8 +36,14 @@ pub fn list_dir(home_dir: &str, requested: &str) -> Result<DirListing, ErrorInfo
|
||||
|
||||
let mut entries: Vec<String> = Vec::new();
|
||||
for entry in read.flatten() {
|
||||
let name = entry.file_name().to_string_lossy().into_owned();
|
||||
// Skip hidden directories — the spawn form rarely targets dotfile dirs
|
||||
// and they only clutter the completion list.
|
||||
if name.starts_with('.') {
|
||||
continue;
|
||||
}
|
||||
if is_dir(&entry) {
|
||||
entries.push(entry.file_name().to_string_lossy().into_owned());
|
||||
entries.push(name);
|
||||
}
|
||||
}
|
||||
// Case-insensitive sort so `Projects` and `projects` interleave the way a
|
||||
@@ -124,12 +130,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_dirs_only_sorted_case_insensitively_including_hidden() {
|
||||
fn lists_visible_dirs_only_sorted_case_insensitively() {
|
||||
let tmp = fixture();
|
||||
let home = tmp.path().to_string_lossy();
|
||||
let listing = list_dir(&home, "").unwrap();
|
||||
// The file is excluded; dirs (incl. hidden + symlinked dir) are present.
|
||||
assert!(listing.entries.contains(&".config".to_string()));
|
||||
// Files and hidden dirs are excluded; visible dirs (incl. a symlinked
|
||||
// dir) are present.
|
||||
assert!(!listing.entries.contains(&".config".to_string()));
|
||||
assert!(listing.entries.contains(&"projects".to_string()));
|
||||
assert!(listing.entries.contains(&"Downloads".to_string()));
|
||||
assert!(!listing.entries.contains(&"notes.txt".to_string()));
|
||||
|
||||
@@ -77,7 +77,7 @@ pub struct DirListing {
|
||||
pub path: PathBuf,
|
||||
/// Immediate subdirectory names (not full paths), sorted case-insensitively.
|
||||
/// Directories only — the spawn form's targets are always dirs. Hidden
|
||||
/// entries (dotfiles) are included, matching shell completion.
|
||||
/// directories (dotfiles) are excluded.
|
||||
pub entries: Vec<String>,
|
||||
/// True when `entries` was truncated at the daemon's cap; the client can
|
||||
/// surface "narrow your search" rather than implying the dir is small.
|
||||
|
||||
Reference in New Issue
Block a user