diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-04 14:33:49 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-04 14:33:49 +0800 |
| commit | b5e14df41a2b77d71e3367fe44bf466f5c8ad1b5 (patch) | |
| tree | a48b4ada977cf82204b34891525e47189b27d6db /mingling_core/src | |
| parent | 5b281566c7ba56d3de1cdc9f0909da6eb32884ab (diff) | |
chore(core): merge custom completions with defaults
When a concrete entry's custom completion handler produces a `Suggest`
value, combine it with the default subcommand suggestions instead of
replacing them entirely. `FileCompletion` still falls back to the
default completion since it cannot be meaningfully merged.
Diffstat (limited to 'mingling_core/src')
| -rw-r--r-- | mingling_core/src/comp.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/mingling_core/src/comp.rs b/mingling_core/src/comp.rs index 5f851ca..edf25a6 100644 --- a/mingling_core/src/comp.rs +++ b/mingling_core/src/comp.rs @@ -168,8 +168,22 @@ impl CompletionHelper { match suggest { Some(suggest) => { + // A concrete entry was dispatched. Merge the entry's own + // completion with the default subcommand suggestions so that, + // e.g. `thanks <tab>`, suggests both the leaf nodes (`bob`, + // `alice`) and the `thanks` entry's own completion. trace!("using custom completion: {:?}", suggest); - suggest + let default = default_completion::<P>(ctx); + if suggest == Suggest::FileCompletion { + trace!( + "custom completion is FileCompletion, using default: {:?}", + default + ); + default + } else { + trace!("combining custom completion with default"); + suggest.combine(default) + } } None => { if first_cmd_match.is_some() { |
