aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/comp
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-15 22:21:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-15 22:21:56 +0800
commit6d61e0c46d33b917438386191e1e11351359abac (patch)
tree93a402007a4ac1a4b561a454ab758480d7213c0d /mingling_core/src/comp
parenta2eefa6abb7b7b86ab78466bf5abc4877d255d79 (diff)
Inline `strip_all_flags` and simplify `ShellContext` methods
Simplify `strip_all_flags` by using `Vec::retain` instead of reallocating. Update doc examples to use `ShellContext` methods directly instead of the now-removed `ShellContextHelper`. Rename `as_picker` to `to_picker` for consistency with Rust conventions. Mark doc tests as `ignore` and add necessary imports.
Diffstat (limited to 'mingling_core/src/comp')
-rw-r--r--mingling_core/src/comp/shell_ctx.rs24
1 files changed, 6 insertions, 18 deletions
diff --git a/mingling_core/src/comp/shell_ctx.rs b/mingling_core/src/comp/shell_ctx.rs
index dd2aa86..3134cd6 100644
--- a/mingling_core/src/comp/shell_ctx.rs
+++ b/mingling_core/src/comp/shell_ctx.rs
@@ -106,14 +106,10 @@ impl ShellContext {
///
/// ```
/// # use mingling_core::ShellContext;
- /// # use mingling_macros::suggest;
- /// # use mingling::comp_tools::ShellContextHelper;
- ///
/// let ctx = ShellContext::default();
- /// let helper = ShellContextHelper::from(ctx);
///
/// // Check if either "--insert" or "-i" appears exactly once
- /// if helper.filling_argument_first(["--insert", "-i"]) {
+ /// if ctx.filling_argument_first(["--insert", "-i"]) {
/// // Perform action that should only happen once, example:
/// // return suggest! {
/// // "A", "B", "C"
@@ -135,7 +131,7 @@ impl ShellContext {
return true;
}
}
- return false;
+ false
}
/// Checks if the previous word in the command line arguments matches any of the given flags.
@@ -148,14 +144,10 @@ impl ShellContext {
///
/// ```
/// # use mingling_core::ShellContext;
- /// # use mingling_macros::suggest;
- /// # use mingling::comp_tools::ShellContextHelper;
- ///
/// let ctx = ShellContext::default();
- /// let helper = ShellContextHelper::from(ctx);
///
/// // Check if the previous word is either "--file" or "-f"
- /// if helper.filling_argument(["--file", "-f"]) {
+ /// if ctx.filling_argument(["--file", "-f"]) {
/// // The user is likely expecting a file argument next, example:
/// // return suggest! {
/// // "src/main.rs", "Cargo.toml", "README.md"
@@ -168,7 +160,7 @@ impl ShellContext {
return true;
}
}
- return false;
+ false
}
/// Checks if the user is currently typing a flag argument.
@@ -188,14 +180,10 @@ impl ShellContext {
///
/// ```
/// # use mingling_core::ShellContext;
- /// # use mingling_macros::suggest;
- /// # use mingling::comp_tools::ShellContextHelper;
- ///
/// let ctx = ShellContext::default();
- /// let helper = ShellContextHelper::from(ctx);
///
/// // Check if the user is typing a flag
- /// if helper.typing_argument() {
+ /// if ctx.typing_argument() {
/// // The user is likely entering a flag, example:
/// // return suggest! {
/// // "--help", "--version", "--verbose"
@@ -220,7 +208,7 @@ impl ShellContext {
/// when the user has already typed certain flags. The method processes both
/// regular suggestion sets and file completion suggestions differently.
pub fn strip_typed_argument(&self, suggest: Suggest) -> Suggest {
- let typed = Self::get_typed_arguments(&self);
+ let typed = Self::get_typed_arguments(self);
match suggest {
Suggest::Suggest(mut set) => {
set.retain(|item| !typed.contains(item.suggest()));