From 402acde5c0c06f827dd6c29e44cdca26483ac7d3 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 14 Dec 2023 18:29:09 +0100 Subject: [PATCH] completes NU_LIB_DIRS with directory modules this checks if `search dir + it + mod.nu` exists and adds that to the completion items if so. i renamed the outter `it` to `search_dir` to avoid it being shadowed by the innermost one and avoid defining a binding with the same name. --- .../nu-cli/src/completions/dotnu_completions.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/nu-cli/src/completions/dotnu_completions.rs b/crates/nu-cli/src/completions/dotnu_completions.rs index fd5c346d95..87a77bd565 100644 --- a/crates/nu-cli/src/completions/dotnu_completions.rs +++ b/crates/nu-cli/src/completions/dotnu_completions.rs @@ -5,7 +5,7 @@ use nu_protocol::{ }; use reedline::Suggestion; use std::{ - path::{is_separator, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR}, + path::{is_separator, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR, Path}, sync::Arc, }; @@ -91,16 +91,21 @@ impl Completer for DotNuCompletion { // and transform them into suggestions let output: Vec = search_dirs .into_iter() - .flat_map(|it| { - file_path_completion(span, &partial, &it, options) + .flat_map(|search_dir| { + let completions = file_path_completion(span, &partial, &search_dir, options); + completions .into_iter() - .filter(|it| { + .filter(move |it| { // Different base dir, so we list the .nu files or folders if !is_current_folder { it.1.ends_with(".nu") || it.1.ends_with(SEP) } else { - // Lib dirs, so we filter only the .nu files - it.1.ends_with(".nu") + // Lib dirs, so we filter only the .nu files or directory modules + if it.1.ends_with(SEP) { + Path::new(&search_dir).join(&it.1).join("mod.nu").exists() + } else { + it.1.ends_with(".nu") + } } }) .map(move |x| Suggestion {