Handle multiple exact matches (#15772)

# Description

Fixes #15734. With case-insensitive matching, when completing a
file/folder, there can be multiple exact matches. For example, if you
have three folders `aa/`, `AA/`, and `aaa/`, `aa/<TAB>` should match all
of them. But, as reported in #15734, when using prefix matching, only
`AA/` will be shown. This is because when there's an exact match in
prefix match mode, we only show the first exact match.

There are two options for fixing this:
- Show all matched suggestions (`aa/`, `AA/`, and `aaa/`)
  - I chose this option
- Show only the suggestions that matched exactly (`aa/` and `AA/`) but
not others (`aaa/`)
  - This felt unintuitive

# User-Facing Changes

As mentioned above, when:
- you have multiple folders with the same name but in different cases
- and you're using prefix matching
- and you're using case-insensitive matching
- and you type in the name of one of these folders exactly

then you'll be suggested every folder matching the typed text, rather
than just exact matches

# Tests + Formatting

I added a test that doesn't run on Windows or MacOS (to avoid
case-insensitive filesystems). While adding this test, I felt like using
`Playground` rather than adding files to `tests/fixtures`. To make this
easier, I refactored the `new_*_engine()` helpers in
`completion_helpers.rs` a bit. There was quite a bit of code duplication
there.

# After Submitting

N/A
This commit is contained in:
Yash Thakur
2025-05-28 09:00:55 -04:00
committed by GitHub
parent 37bc922a67
commit adc9bbdc18
3 changed files with 92 additions and 132 deletions

View File

@ -2346,6 +2346,32 @@ fn exact_match() {
assert!(suggestions.len() > 1);
}
#[cfg(all(not(windows), not(target_os = "macos")))]
#[test]
fn exact_match_case_insensitive() {
use nu_test_support::playground::Playground;
use support::completions_helpers::new_engine_helper;
Playground::setup("exact_match_case_insensitive", |dirs, playground| {
playground.mkdir("AA/foo");
playground.mkdir("aa/foo");
playground.mkdir("aaa/foo");
let (dir, _, engine, stack) = new_engine_helper(dirs.test().into());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target = format!("open {}", folder(dir.join("aa")));
match_suggestions(
&vec![
folder(dir.join("AA").join("foo")).as_str(),
folder(dir.join("aa").join("foo")).as_str(),
folder(dir.join("aaa").join("foo")).as_str(),
],
&completer.complete(&target, target.len()),
);
});
}
#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7648() {