aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-03 14:32:32 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-03 14:34:06 +0800
commit52a448ca246d60f4cf88bdcde73bfed0f989c848 (patch)
tree016c61e970d81b5beeafa6cbc2cc1eeb7aa8999b
parentf0c2f456d6762f4219cfc0679660ad526e5faa59 (diff)
chore: add EntryFallback completion support
Add `#[completion(EntryFallback)]` syntax to enable custom completion suggestions for unmatched entries, merging fallback results with default completions via `Suggest::combine()`.
-rw-r--r--CHANGELOG.md23
-rw-r--r--docs/dev/pages/issues/the-shit-time.md13
-rw-r--r--mingling_core/src/comp.rs4
3 files changed, 38 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c954123..6062103 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -168,6 +168,29 @@ None
Also reorganized the `[features]` section of `mingling/Cargo.toml` into logical subsections (Presets, Core, Special features, Features, LEGACY) for improved maintainability and documentation.
+8. **[`core`]** **[`macros`]** Added the `#[completion(EntryFallback)]` syntax to the `#[completion]` macro, mirroring the `#[help(EntryFallback)]` pattern. When the `EntryFallback` identifier is passed (either as a bare path in the attribute arguments), the macro generates a chain handler for the `EntryFallback` type (the program's fallback entry pack type generated by `gen_program!()`). This handler is invoked during the default-completion path when no explicit dispatcher match is found.
+
+ When the program's dispatcher fails to find a match in the completion pipeline, the `CompletionHelper::complete` method now:
+
+ - Checks for an explicit completion handler via the chain pipeline for the `EntryFallback` type (calling `P::do_comp(&P::build_entry_fallback(vec![]), ctx)`).
+ - If that produces suggestions, they are combined with the default completion suggestions via `Suggest::combine()` (which merges `BTreeSet`s for `Suggest::Suggest` values).
+ - Falls back to the standard `default_completion::<P>(ctx)` behavior when no explicit fallback handler yields results.
+
+ This enables users to provide custom completion suggestions for the fallback/unmatched case:
+
+ ```rust,ignore
+ #[completion(EntryFallback)]
+ fn complete_fallback(_ctx: &ShellContext) -> Suggest {
+ suggest! { "fallback" }
+ }
+ ```
+
+ The generated chain handler for `EntryFallback` is identical to how `#[chain]`-annotated functions targeting entry pack types work — the `EntryFallback` type name is resolved through the same `chain` code-generation path used for `Entry{Type}` types, allowing users to write a dedicated completion function for the fallback entry point without manually registering it in the program's dispatcher.
+
+ Internal changes:
+ - `mingling_macros/src/attr/completion.rs` updated to detect the `EntryFallback` identifier in attribute arguments.
+ - `CompletionHelper::complete` in `mingling_core/src/comp.rs` now invokes the fallback completion handler via `P::do_comp(&P::build_entry_fallback(vec![]), ctx)` and merges results with `Suggest::combine()`.
+
#### **BREAKING CHANGES** (API CHANGES):
1. **[`macros`]** **[BREAKING]** Renamed the `extra_macros` feature to `extras`. All feature-gated macro re-exports in `mingling/src/lib.rs` (and throughout the codebase) have been updated from `#[cfg(feature = "extra_macros")]` to `#[cfg(feature = "extras")]`.
diff --git a/docs/dev/pages/issues/the-shit-time.md b/docs/dev/pages/issues/the-shit-time.md
index 9d6c429..b23854e 100644
--- a/docs/dev/pages/issues/the-shit-time.md
+++ b/docs/dev/pages/issues/the-shit-time.md
@@ -9,7 +9,7 @@ Of course, you can also contribute to this document.
---
-## Why is there no fallback completion logic?
+## Why is there no fallback completion logic? (Solved)
(completion) (fallback)
@@ -34,6 +34,17 @@ fn complete(ctx: &ShellContext) -> Suggest {
// ...
}
```
+
+Final implementation:
+
+By adding support for `EntryFallback` (formerly `ErrorDispatcherNotFound`) to the Completion system, `EntryFallback` can now be used as a completion entry point when no subcommand is matched:
+
+```rust
+#[completion(EntryFallback)]
+fn complete_fallback(_ctx: &ShellContext) -> Suggest {
+ suggest! { "fallback" }
+}
+```
---
diff --git a/mingling_core/src/comp.rs b/mingling_core/src/comp.rs
index a4e4f0b..021793b 100644
--- a/mingling_core/src/comp.rs
+++ b/mingling_core/src/comp.rs
@@ -163,7 +163,9 @@ impl CompletionHelper {
}
None => {
trace!("using default completion");
- default_completion::<P>(ctx)
+ let fallback = P::do_comp(&P::build_entry_fallback(vec![]), ctx);
+ let default = default_completion::<P>(ctx);
+ fallback.combine(default)
}
}
}