diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-29 13:24:10 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-29 13:24:10 +0800 |
| commit | 2234df5cc195c4d6734d10ed6b4d08d5497b4bf7 (patch) | |
| tree | d9211edc8e56123dc91fe03f3d365c29ccc5e652 | |
| parent | 18acfba07497ff5554f2790a170d003ed6a7dbfb (diff) | |
feat(core/comp): add Suggest::combine method for merging suggestions
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | mingling_core/src/comp/suggest.rs | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe8be1..3130abc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,6 +140,8 @@ None 6. **[`macros:gen_program`]** Added a `pack!(Entry = Vec<String>)` invocation inside the `__this_program_impl` module generated by `gen_program!()`. This creates a `Entry` pack type (aliasing a `Vec<String>` container) directly in the generated module, providing a default entry point type for the program that can be used by `dispatcher!()`-generated types and other chain infrastructure without requiring the user to define a separate entry pack type manually. +7. **[`core`]** **[`comp`]** Added `Suggest::combine(self, other: impl Into<Suggest>) -> Self` method that merges two `Suggest` values. If both are `Suggest::Suggest`, their inner `BTreeSet`s are merged (all items from `other` are added into `self`). Otherwise, the first `Suggest::Suggest` (or `FileCompletion`) is returned unchanged, and the other value is discarded. This enables ergonomic aggregation of completion suggestions from multiple sources. + #### **BREAKING CHANGES** (API CHANGES): None diff --git a/mingling_core/src/comp/suggest.rs b/mingling_core/src/comp/suggest.rs index 99afc54..88fa5fc 100644 --- a/mingling_core/src/comp/suggest.rs +++ b/mingling_core/src/comp/suggest.rs @@ -41,6 +41,21 @@ impl Suggest { pub fn strip_typed_argument(self, ctx: &ShellContext) -> Self { ctx.strip_typed_argument(self) } + + /// Combines two `Suggest` values. + /// + /// If both values are `Suggest::Suggest`, their `BTreeSet`s are merged + /// (all items from `other` are added into `self`). Otherwise, the first + /// `Suggest::Suggest` (or `FileCompletion`) is returned unchanged. + pub fn combine(self, other: impl Into<Suggest>) -> Self { + let other = other.into(); + match (self, other) { + (Suggest::Suggest(suggest), Suggest::Suggest(other)) => { + Suggest::Suggest(suggest.into_iter().chain(other).collect()) + } + (suggest, _) => suggest, + } + } } impl<T> From<T> for Suggest |
