Skip to content

Commit 8b0e364

Browse files
committed
Hide "did you mean" when no suggestions are found
When a typo has no fuzzy matches, show only "Task X not found." instead of "Task X not found. Did you mean:" with an empty list. https://claude.ai/code/session_01QVjgsRa8uw66PsSyAJNBjp
1 parent 4284494 commit 8b0e364

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

crates/vite_select/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ fn non_interactive(
9595
before_render(&mut filtered, query.unwrap_or_default());
9696
let len = filtered.len();
9797

98+
// When there are no matching items, just print the header (if any) and
99+
// return early — avoids showing a redundant "No matching tasks." line
100+
// after a "not found" header.
101+
if filtered.is_empty() {
102+
if let Some(h) = header {
103+
writeln!(writer, "{h}")?;
104+
}
105+
return Ok(());
106+
}
107+
98108
render_items(
99109
writer,
100110
&RenderParams {

crates/vite_task/src/session/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,20 @@ impl<'a> Session<'a> {
378378
})
379379
.collect();
380380

381-
// Build header: interactive says "not found.", non-interactive "did you mean:" suffix
381+
// Build header: interactive says "not found.", non-interactive adds
382+
// "Did you mean:" suffix only when there are fuzzy matches to show.
382383
let header = not_found_name.map(|name| {
383384
if is_interactive {
384385
vite_str::format!("Task \"{name}\" not found.")
385386
} else {
386-
vite_str::format!("Task \"{name}\" not found. Did you mean:")
387+
let labels: Vec<&str> =
388+
select_items.iter().map(|item| item.label.as_str()).collect();
389+
let has_suggestions = !vite_select::fuzzy_match(name, &labels).is_empty();
390+
if has_suggestions {
391+
vite_str::format!("Task \"{name}\" not found. Did you mean:")
392+
} else {
393+
vite_str::format!("Task \"{name}\" not found.")
394+
}
387395
}
388396
});
389397

crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ steps = [
1212
"echo '' | vp run buid",
1313
]
1414

15+
# Non-interactive: typo with no fuzzy matches hides "did you mean"
16+
[[e2e]]
17+
name = "non-interactive no suggestions"
18+
steps = [
19+
"echo '' | vp run zzzzz",
20+
]
21+
1522
# Non-interactive: typo with -r flag errors (not cwd_only)
1623
[[e2e]]
1724
name = "non-interactive recursive typo errors"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
---
5+
[1]> echo '' | vp run zzzzz
6+
Task "zzzzz" not found.

0 commit comments

Comments
 (0)