aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/comp
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_core/src/comp')
-rw-r--r--mingling_core/src/comp/flags.rs2
-rw-r--r--mingling_core/src/comp/shell_ctx.rs12
-rw-r--r--mingling_core/src/comp/suggest.rs23
3 files changed, 23 insertions, 14 deletions
diff --git a/mingling_core/src/comp/flags.rs b/mingling_core/src/comp/flags.rs
index 452126b..424fe8b 100644
--- a/mingling_core/src/comp/flags.rs
+++ b/mingling_core/src/comp/flags.rs
@@ -14,7 +14,7 @@ pub enum ShellFlag {
Zsh,
/// Represents the Fish shell.
Fish,
- /// Represents PowerShell.
+ /// Represents `PowerShell`.
Powershell,
/// A custom or unsupported shell type, identified by the provided string.
Other(String),
diff --git a/mingling_core/src/comp/shell_ctx.rs b/mingling_core/src/comp/shell_ctx.rs
index 3134cd6..35758e9 100644
--- a/mingling_core/src/comp/shell_ctx.rs
+++ b/mingling_core/src/comp/shell_ctx.rs
@@ -73,8 +73,7 @@ impl TryFrom<Vec<String>> for ShellContext {
let shell_flag = arg_map
.get("-F")
.cloned()
- .map(ShellFlag::from)
- .unwrap_or(ShellFlag::Other("unknown".to_string()));
+ .map_or(ShellFlag::Other("unknown".to_string()), ShellFlag::from);
let all_words = command_line
.split_whitespace()
@@ -120,7 +119,7 @@ impl ShellContext {
let flag = flag.into();
if self.filling_argument(&flag) {
let mut flag_appears = 0;
- for w in self.all_words.iter() {
+ for w in &self.all_words {
for f in flag.iter() {
if *f == w {
flag_appears += 1;
@@ -190,6 +189,7 @@ impl ShellContext {
/// // }
/// }
/// ```
+ #[must_use]
pub fn typing_argument(&self) -> bool {
#[cfg(target_os = "windows")]
{
@@ -207,6 +207,7 @@ impl ShellContext {
/// in the command line. It is useful for preventing duplicate flag suggestions
/// when the user has already typed certain flags. The method processes both
/// regular suggestion sets and file completion suggestions differently.
+ #[must_use]
pub fn strip_typed_argument(&self, suggest: Suggest) -> Suggest {
let typed = Self::get_typed_arguments(self);
match suggest {
@@ -223,11 +224,12 @@ impl ShellContext {
/// This method collects all words in the shell context that start with a dash (`-`),
/// which typically represent command-line flags or options. It returns a vector
/// containing these flag strings, converted to owned `String` values.
+ #[must_use]
pub fn get_typed_arguments(&self) -> HashSet<String> {
self.all_words
.iter()
- .filter(|word| word.starts_with("-"))
- .map(|word| word.to_string())
+ .filter(|word| word.starts_with('-'))
+ .cloned()
.collect()
}
}
diff --git a/mingling_core/src/comp/suggest.rs b/mingling_core/src/comp/suggest.rs
index 6d64341..cd025a4 100644
--- a/mingling_core/src/comp/suggest.rs
+++ b/mingling_core/src/comp/suggest.rs
@@ -16,17 +16,20 @@ pub enum Suggest {
}
impl Suggest {
- /// Creates a new Suggest variant containing a BTreeSet of suggestions.
+ /// Creates a new Suggest variant containing a `BTreeSet` of suggestions.
+ #[must_use]
pub fn new() -> Self {
Self::Suggest(BTreeSet::new())
}
- /// Creates a FileCompletion variant.
+ /// Creates a `FileCompletion` variant.
+ #[must_use]
pub fn file_comp() -> Self {
Self::FileCompletion
}
/// Filters out already typed flag arguments from suggestion results.
+ #[must_use]
pub fn strip_typed_argument(self, ctx: &ShellContext) -> Self {
ctx.strip_typed_argument(self)
}
@@ -103,40 +106,44 @@ impl Ord for SuggestItem {
impl SuggestItem {
/// Creates a new simple suggestion without description.
+ #[must_use]
pub fn new(suggest: String) -> Self {
Self::Simple(suggest)
}
/// Creates a new suggestion with a description.
+ #[must_use]
pub fn new_with_desc(suggest: String, description: String) -> Self {
Self::WithDescription(suggest, description)
}
/// Adds a description to this suggestion, replacing any existing description.
+ #[must_use]
pub fn with_desc(self, description: String) -> Self {
match self {
- Self::Simple(suggest) => Self::WithDescription(suggest, description),
- Self::WithDescription(suggest, _) => Self::WithDescription(suggest, description),
+ Self::Simple(suggest) | Self::WithDescription(suggest, _) => {
+ Self::WithDescription(suggest, description)
+ }
}
}
/// Returns the suggestion text.
+ #[must_use]
pub fn suggest(&self) -> &String {
match self {
- Self::Simple(suggest) => suggest,
- Self::WithDescription(suggest, _) => suggest,
+ Self::Simple(suggest) | Self::WithDescription(suggest, _) => suggest,
}
}
/// Updates the suggestion text.
pub fn set_suggest(&mut self, new_suggest: String) {
match self {
- Self::Simple(suggest) => *suggest = new_suggest,
- Self::WithDescription(suggest, _) => *suggest = new_suggest,
+ Self::Simple(suggest) | Self::WithDescription(suggest, _) => *suggest = new_suggest,
}
}
/// Returns the description if present.
+ #[must_use]
pub fn description(&self) -> Option<&String> {
match self {
Self::Simple(_) => None,