aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md8
-rw-r--r--mingling/src/lib.rs4
-rw-r--r--mingling/src/picker_comp.rs52
3 files changed, 64 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3130abc..1cf0c80 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -142,6 +142,14 @@ None
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.
+8. **[`picker_comp`]** Added `mingling::picker_comp` module behind `cfg(all(feature = "picker", feature = "comp"))` with a `PickerArgSuggest` trait and its implementation for `&PickerArg<'a, T>`. The trait provides:
+
+ - **`into_suggest(self)`** — Converts the picker argument's known flags into a `Suggest` collection of `SuggestItem::Simple` entries.
+ - **`into_suggest_with_desc(self, description)`** — Same as `into_suggest` but wraps each flag in `SuggestItem::WithDescription`.
+ - **`into_suggest_raw(self, description: Option<&String>)`** — The core method; builds the list of possible flags from `arg_picker::parselib::build_possible_flags` and inserts each into the `Suggest` set, optionally carrying a description.
+
+ This bridges the `picker` and `comp` (completion) subsystems, allowing picker arguments to be reused as completion candidates.
+
#### **BREAKING CHANGES** (API CHANGES):
None
diff --git a/mingling/src/lib.rs b/mingling/src/lib.rs
index d7c8e8f..8f2540c 100644
--- a/mingling/src/lib.rs
+++ b/mingling/src/lib.rs
@@ -24,6 +24,10 @@ pub mod parser;
#[cfg(feature = "picker")]
pub mod picker;
+/// Functionality when combining `picker` and `comp`
+#[cfg(all(feature = "picker", feature = "comp"))]
+pub mod picker_comp;
+
mod constants;
/// Constants used throughout the Mingling framework.
diff --git a/mingling/src/picker_comp.rs b/mingling/src/picker_comp.rs
new file mode 100644
index 0000000..26b0b5a
--- /dev/null
+++ b/mingling/src/picker_comp.rs
@@ -0,0 +1,52 @@
+use arg_picker::{Pickable, PickerArg, PickerArgInfo, parselib::ParserStyle};
+use mingling_core::{Suggest, SuggestItem};
+
+/// Trait for converting picker arguments into `Suggest` items for autocompletion.
+///
+/// This trait is implemented for `PickerArg` references and provides methods to
+/// generate completion suggestions with optional descriptions.
+pub trait PickerArgSuggest {
+ #[doc(hidden)]
+ fn into_suggest_raw(self, description: Option<&String>) -> Suggest;
+
+ /// Converts the picker argument into a `Suggest` with the given description.
+ ///
+ /// The description is used when the suggestion item supports additional text,
+ /// such as `SuggestItem::WithDescription`.
+ fn into_suggest_with_desc(self, description: impl Into<String>) -> Suggest
+ where
+ Self: Sized,
+ {
+ let desc = description.into();
+ self.into_suggest_raw(Some(&desc))
+ }
+
+ /// Converts the picker argument into a `Suggest` without a description.
+ ///
+ /// The resulting suggestion will use `SuggestItem::Simple` for each possible flag.
+ fn into_suggest(self) -> Suggest
+ where
+ Self: Sized,
+ {
+ self.into_suggest_raw(None)
+ }
+}
+
+impl<'a, T> PickerArgSuggest for &'a PickerArg<'a, T>
+where
+ T: Pickable<'a>,
+{
+ fn into_suggest_raw(self, description: Option<&String>) -> Suggest {
+ let mut suggest = Suggest::new();
+ let info = PickerArgInfo::from(self);
+ let possible_flags =
+ arg_picker::parselib::build_possible_flags(ParserStyle::global_style(), &info);
+ for flag in possible_flags {
+ match description {
+ Some(desc) => suggest.insert(SuggestItem::WithDescription(flag, desc.clone())),
+ None => suggest.insert(SuggestItem::Simple(flag)),
+ };
+ }
+ suggest
+ }
+}