diff options
Diffstat (limited to 'mingling_core')
| -rw-r--r-- | mingling_core/src/comp/suggest.rs | 15 |
1 files changed, 15 insertions, 0 deletions
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 |
