aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/comp
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-10 15:49:31 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-10 15:49:31 +0800
commita9d5943939261e27e58bcf5cacbb618a0f63e999 (patch)
treed1cacc2af939e993f2d7d2794500e6456659e6a9 /mingling_core/src/comp
parent782d2458dc4ad4336e1407e1f107e43e39b0b991 (diff)
refactor(core): improve code style and public API clarity
Replace bool-based settings with enums, refine visibility and signatures, and standardize `Self` usage across the crate. - Introduce `ErrorOutput`, `RenderOutput`, `PanicSilence`, `Verbosity`, `ColorOutput`, and `ProgressOutput` enums for clearer configuration semantics - Make `GlobalResources`, `ProgramCell`, and `split_input`/`split_input_string` public - Change hook info parameters to accept references and `split_input_string` to take `&str` - Apply `Self` shorthand throughout implementations and add `#[must_use]` attributes where appropriate - Enable strict clippy lints with targeted allowances
Diffstat (limited to 'mingling_core/src/comp')
-rw-r--r--mingling_core/src/comp/comp_ctx.rs1
-rw-r--r--mingling_core/src/comp/flags.rs10
-rw-r--r--mingling_core/src/comp/shell_ctx.rs4
-rw-r--r--mingling_core/src/comp/suggest.rs43
4 files changed, 31 insertions, 27 deletions
diff --git a/mingling_core/src/comp/comp_ctx.rs b/mingling_core/src/comp/comp_ctx.rs
index 8d7fa5c..6384909 100644
--- a/mingling_core/src/comp/comp_ctx.rs
+++ b/mingling_core/src/comp/comp_ctx.rs
@@ -10,6 +10,7 @@ where
/// (defined by [`COMPLETION_SUBCOMMAND`]) appears among the parsed arguments.
/// When `true`, the program should generate shell completions instead of
/// running its normal execution path.
+ #[must_use]
pub fn is_completing(&self) -> bool {
// Check if the first argument (args[1]) is the completion subcommand
self.args
diff --git a/mingling_core/src/comp/flags.rs b/mingling_core/src/comp/flags.rs
index 8aecf1b..0867122 100644
--- a/mingling_core/src/comp/flags.rs
+++ b/mingling_core/src/comp/flags.rs
@@ -23,11 +23,11 @@ pub enum ShellFlag {
impl From<String> for ShellFlag {
fn from(s: String) -> Self {
match s.trim().to_lowercase().as_str() {
- "zsh" => ShellFlag::Zsh,
- "bash" => ShellFlag::Bash,
- "fish" => ShellFlag::Fish,
- "pwsh" | "ps1" | "powershell" => ShellFlag::Powershell,
- other => ShellFlag::Other(snake_case!(other)),
+ "zsh" => Self::Zsh,
+ "bash" => Self::Bash,
+ "fish" => Self::Fish,
+ "pwsh" | "ps1" | "powershell" => Self::Powershell,
+ other => Self::Other(snake_case!(other)),
}
}
}
diff --git a/mingling_core/src/comp/shell_ctx.rs b/mingling_core/src/comp/shell_ctx.rs
index 734b5d2..ceb433f 100644
--- a/mingling_core/src/comp/shell_ctx.rs
+++ b/mingling_core/src/comp/shell_ctx.rs
@@ -64,7 +64,7 @@ impl TryFrom<Vec<String>> for ShellContext {
.map(|s| s.replace('^', "-"))
.collect();
- Ok(ShellContext {
+ Ok(Self {
command_line: command_line.replace('^', "-"),
cursor_position,
current_word: current_word.replace('^', "-"),
@@ -201,7 +201,7 @@ impl ShellContext {
}
#[cfg(not(target_os = "windows"))]
{
- self.current_word.starts_with("-")
+ self.current_word.starts_with('-')
}
}
diff --git a/mingling_core/src/comp/suggest.rs b/mingling_core/src/comp/suggest.rs
index 804d622..27b227f 100644
--- a/mingling_core/src/comp/suggest.rs
+++ b/mingling_core/src/comp/suggest.rs
@@ -18,15 +18,15 @@ pub enum Suggest {
}
impl Suggest {
- /// Creates a new Suggest variant containing a `BTreeSet` of suggestions.
+ /// Creates a new `Suggest` variant containing an empty `BTreeSet` of suggestions.
#[must_use]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
Self::Suggest(BTreeSet::new())
}
/// Creates a `FileCompletion` variant.
#[must_use]
- pub fn file_comp() -> Self {
+ pub const fn file_comp() -> Self {
Self::FileCompletion
}
@@ -47,11 +47,12 @@ impl Suggest {
/// 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 {
+ #[must_use]
+ pub fn combine(self, other: impl Into<Self>) -> Self {
let other = other.into();
match (self, other) {
- (Suggest::Suggest(suggest), Suggest::Suggest(other)) => {
- Suggest::Suggest(suggest.into_iter().chain(other).collect())
+ (Self::Suggest(suggest), Self::Suggest(other)) => {
+ Self::Suggest(suggest.into_iter().chain(other).collect())
}
(suggest, _) => suggest,
}
@@ -109,10 +110,11 @@ impl Suggest {
/// A new `Suggest` value where each item's suggestion text is prefixed
/// with the given string. For example, `["foo", "bar"]` with prefix `"--"`
/// becomes `["--foo", "--bar"]`.
- pub fn add_prefix(self, prefix: impl Into<String>) -> Suggest {
+ #[must_use]
+ pub fn add_prefix(self, prefix: impl Into<String>) -> Self {
let suggest = match self {
- Suggest::Suggest(s) => s,
- Suggest::FileCompletion => return Suggest::FileCompletion,
+ Self::Suggest(s) => s,
+ Self::FileCompletion => return Self::FileCompletion,
};
let prefix = prefix.into();
let prefixed = suggest
@@ -123,7 +125,7 @@ impl Suggest {
new_item
})
.collect();
- Suggest::Suggest(prefixed)
+ Self::Suggest(prefixed)
}
/// Appends a suffix to every suggestion in the `Suggest` set.
@@ -142,10 +144,11 @@ impl Suggest {
/// A new `Suggest` value where each item's suggestion text is suffixed
/// with the given string. For example, `["foo", "bar"]` with suffix `"="`
/// becomes `["foo=", "bar="]`.
- pub fn add_suffix(self, suffix: impl Into<String>) -> Suggest {
+ #[must_use]
+ pub fn add_suffix(self, suffix: impl Into<String>) -> Self {
let suggest = match self {
- Suggest::Suggest(s) => s,
- Suggest::FileCompletion => return Suggest::FileCompletion,
+ Self::Suggest(s) => s,
+ Self::FileCompletion => return Self::FileCompletion,
};
let suffix = suffix.into();
let suffixed = suggest
@@ -156,7 +159,7 @@ impl Suggest {
new_item
})
.collect();
- Suggest::Suggest(suffixed)
+ Self::Suggest(suffixed)
}
}
@@ -170,7 +173,7 @@ where
.into_iter()
.map(|item| SuggestItem::new(item.into()))
.collect();
- Suggest::Suggest(suggests)
+ Self::Suggest(suggests)
}
}
@@ -213,7 +216,7 @@ pub enum SuggestItem {
impl Default for SuggestItem {
fn default() -> Self {
- SuggestItem::Simple(String::new())
+ Self::Simple(String::new())
}
}
@@ -232,13 +235,13 @@ impl Ord for SuggestItem {
impl SuggestItem {
/// Creates a new simple suggestion without description.
#[must_use]
- pub fn new(suggest: String) -> Self {
+ pub const 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 {
+ pub const fn new_with_desc(suggest: String, description: String) -> Self {
Self::WithDescription(suggest, description)
}
@@ -254,7 +257,7 @@ impl SuggestItem {
/// Returns the suggestion text.
#[must_use]
- pub fn suggest(&self) -> &String {
+ pub const fn suggest(&self) -> &String {
match self {
Self::Simple(suggest) | Self::WithDescription(suggest, _) => suggest,
}
@@ -269,7 +272,7 @@ impl SuggestItem {
/// Returns the description if present.
#[must_use]
- pub fn description(&self) -> Option<&String> {
+ pub const fn description(&self) -> Option<&String> {
match self {
Self::Simple(_) => None,
Self::WithDescription(_, description) => Some(description),