diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 05:49:19 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 05:49:19 +0800 |
| commit | 57c53affe3542cb6bd4e79ee4c18f20a1bd76b2d (patch) | |
| tree | 1cd4aef44cb7a45a8cd9d520b598f5f181e24c76 /mingling_cli/src/linter | |
| parent | ef23cd944402939605c78a4a853ef6e33af02c21 (diff) | |
refactor!: replace pack! macros with derive-based pipeline types
Remove the `pack!`, `pack_err!`, `pack_structural!`, and
`pack_err_structural!` macros, replacing all pipeline type definitions
with `#[derive(Grouped)]` and `#[derive(Grouped, Wrap)]` attributes.
This changes the generated struct shape from named-field structs with an
`inner` field to tuple structs accessed via `.0`, and removes the
auto-generated `name` and `info` fields from error types.
Diffstat (limited to 'mingling_cli/src/linter')
| -rw-r--r-- | mingling_cli/src/linter/cmd_explain.rs | 30 | ||||
| -rw-r--r-- | mingling_cli/src/linter/cmd_lint.rs | 12 | ||||
| -rw-r--r-- | mingling_cli/src/linter/mlint_report.rs | 21 |
3 files changed, 34 insertions, 29 deletions
diff --git a/mingling_cli/src/linter/cmd_explain.rs b/mingling_cli/src/linter/cmd_explain.rs index 5346255..923e890 100644 --- a/mingling_cli/src/linter/cmd_explain.rs +++ b/mingling_cli/src/linter/cmd_explain.rs @@ -1,10 +1,7 @@ use crate::{Next, eprintln_cargo, linter::registry::ResLintRegistry}; use mingling::{ - Grouped, LazyRes, RenderResult, Routable, ShellContext, Suggest, SuggestItem, - macros::{ - arg, buffer, chain, completion, dispatcher, metadata, pack, pack_err, r_println, renderer, - routeify, - }, + Grouped, LazyRes, RenderResult, Routable, ShellContext, Suggest, SuggestItem, Wrap, + macros::{arg, buffer, chain, completion, dispatcher, metadata, r_println, renderer, routeify}, metadata::Description, picker::EntryPicker, }; @@ -16,9 +13,14 @@ pub fn desc_explain() -> Description { "Explain the meaning of the specified Lint".into() } -pack!(StateExplainLint = String); -pack_err!(ErrorNoExplainLintProvided); -pack_err!(ErrorNoSuchLint = String); +#[derive(Grouped, Wrap)] +pub struct StateExplainLint(String); + +#[derive(Grouped, Default)] +pub struct ErrorNoExplainLintProvided; + +#[derive(Grouped, Wrap)] +pub struct ErrorNoSuchLint(String); #[derive(Debug, Default, Grouped)] pub struct ResultExplainLint { @@ -33,11 +35,9 @@ pub struct ResultExplainLint { #[chain(routeify)] pub fn handle_explain(args: EntryExplain) -> Next { let lint_name = args - .pick_or_route(&arg![String], || { - ErrorNoExplainLintProvided::default().to_chain() - }) + .pick_or_route(&arg![String], || ErrorNoExplainLintProvided.to_chain()) .to_result()?; - StateExplainLint::new(lint_name).into() + StateExplainLint(lint_name).into() } #[chain] @@ -46,9 +46,9 @@ pub fn handle_state_explain_lint( registry: &mut LazyRes<ResLintRegistry>, ) -> Next { let registry = registry.get_ref(); - let lint_name = p.inner; + let lint_name = p.0; let Some(entry) = registry.lints.iter().find(|l| l.name == lint_name) else { - return ErrorNoSuchLint::new(lint_name).to_chain(); + return ErrorNoSuchLint(lint_name).to_chain(); }; ResultExplainLint { lint_name: entry.name.clone(), @@ -87,7 +87,7 @@ pub fn render_error_no_such_lint( ) -> RenderResult { let mut r = RenderResult::new(); let registry = registry.get_ref(); - eprintln_cargo!(r, "No such lint: \"{}\"", err.info); + eprintln_cargo!(r, "No such lint: \"{}\"", err.0); r_println!(r, ""); r_println!(r, "Available lints:"); for entry in registry.lints.iter() { diff --git a/mingling_cli/src/linter/cmd_lint.rs b/mingling_cli/src/linter/cmd_lint.rs index 07c18c5..7cab63a 100644 --- a/mingling_cli/src/linter/cmd_lint.rs +++ b/mingling_cli/src/linter/cmd_lint.rs @@ -1,10 +1,11 @@ use crate::linter::mlint_report::{MlintReport, StateLintReports}; use cargo_metadata::Metadata; use mingling::consts::REMAINS; -use mingling::macros::{arg, chain, completion, dispatcher, metadata, pack, suggest}; +use mingling::macros::{arg, chain, completion, dispatcher, metadata, suggest}; use mingling::metadata::Description; use mingling::picker::parselib::ParserStyle; use mingling::picker::{EntryPicker, PickerArg}; +use mingling::{Grouped, Wrap}; use mingling::{LazyRes, ShellContext, Suggest}; use tokio::task::JoinSet; @@ -77,7 +78,8 @@ async fn linter_main(metadata: &Metadata) -> Vec<MlintReport> { all_reports } -pack!(StateBeginLinter = ()); +#[derive(Grouped, Wrap)] +pub struct StateBeginLinter(()); #[chain] pub fn handle_lint(args: EntryLint) -> StateBeginLinter { @@ -88,7 +90,7 @@ pub fn handle_lint(args: EntryLint) -> StateBeginLinter { // If with_checker is not set, proceed directly to the mingling lint phase let Some(with_checker) = with_checker else { - return StateBeginLinter::new(()); + return StateBeginLinter(()); }; let with_checker: Vec<&str> = with_checker.split(',').collect(); @@ -97,7 +99,7 @@ pub fn handle_lint(args: EntryLint) -> StateBeginLinter { // Run the outer checker (e.g. cargo check) with output passed through directly execute_checker(&with_checker, checker_args.as_slice()); - StateBeginLinter::new(()) + StateBeginLinter(()) } /// Run the outer checker (e.g. cargo check) with output passed through directly. @@ -135,7 +137,7 @@ pub async fn handle_state_begin_linter( ) -> StateLintReports { let metadata = metadata.get_ref().data(); let reports = linter_main(metadata).await; - StateLintReports::new(reports) + StateLintReports(reports) } #[completion(EntryLint)] diff --git a/mingling_cli/src/linter/mlint_report.rs b/mingling_cli/src/linter/mlint_report.rs index b594b9d..d7bf652 100644 --- a/mingling_cli/src/linter/mlint_report.rs +++ b/mingling_cli/src/linter/mlint_report.rs @@ -9,8 +9,8 @@ use cargo_metadata::{Message, PackageId}; use annotate_snippets::level::{ERROR, HELP, NOTE, WARNING}; use annotate_snippets::{AnnotationKind, Group, Patch, Renderer, Snippet}; -use mingling::macros::{buffer, chain, pack, r_append, r_eprintln, renderer}; -use mingling::{RendererInvoker, Routable}; +use mingling::macros::{buffer, chain, r_append, r_eprintln, renderer}; +use mingling::{Grouped, RendererInvoker, Routable, Wrap}; use crate::Next; use crate::metadata::setup::ResUsingJson; @@ -416,22 +416,25 @@ impl MlintReport { } } -pack!(StateLintReports = Vec<MlintReport>); -pack!(ResultLintReportsAnnotateSnippet = Vec<MlintReport>); -pack!(ResultLintReportsJson = Vec<MlintReport>); +#[derive(Grouped, Wrap)] +pub struct StateLintReports(pub Vec<MlintReport>); +#[derive(Grouped, Wrap)] +pub struct ResultLintReportsAnnotateSnippet(Vec<MlintReport>); +#[derive(Grouped, Wrap)] +pub struct ResultLintReportsJson(Vec<MlintReport>); #[chain] pub fn handle_state_lint_reports(reports: StateLintReports, using_json: &ResUsingJson) -> Next { if using_json.using { - ResultLintReportsJson::new(reports.inner).to_render() + ResultLintReportsJson(reports.0).to_render() } else { - ResultLintReportsAnnotateSnippet::new(reports.inner).to_render() + ResultLintReportsAnnotateSnippet(reports.0).to_render() } } #[renderer(buffer)] pub fn render_lint_reports(reports: ResultLintReportsAnnotateSnippet) { - for report in reports.inner { + for report in reports.0 { r_eprintln!("{}", report.to_annotate_snippet_render()); } } @@ -441,7 +444,7 @@ pub fn render_lint_reports_json( reports: ResultLintReportsJson, message_renderer: &RendererInvoker<Message>, ) { - for report in reports.inner { + for report in reports.0 { let message = report.to_compiler_message(); let result = message_renderer.invoke(message); r_append!(result); |
