Skip to content

Commit

Permalink
feat: count total matches
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Aug 6, 2024
1 parent 3681506 commit 709cacb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crates/core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ impl MatchResult {
}
}

pub fn get_ranges(&self) -> Option<&Vec<Range>> {
fs::extract_ranges(self)
}

/// Given a MatchResult, create a MatchResult::Rewrite that suppresses the match.
/// Returns None if it has any issues.
pub fn get_rewrite_to_suppress<'a>(
Expand Down Expand Up @@ -698,7 +702,9 @@ pub struct Message {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
pub struct AllDone {
/// How many files have been processed
pub processed: i32,
/// How many matches were found
pub found: i32,
pub reason: AllDoneReason,
}
Expand Down
5 changes: 4 additions & 1 deletion crates/marzano_messenger/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{format::format_result, workflows::PackagedWorkflowOutcome, SimpleLog

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct ApplyDetails {
/// How many matches were found total (total match range count)
pub matched: i32,
pub rewritten: i32,
pub named_pattern: Option<String>,
Expand Down Expand Up @@ -110,7 +111,9 @@ pub trait Messager: Send + Sync {
) -> anyhow::Result<bool> {
for r in execution_result {
if is_match(&r) {
details.matched += 1;
if let Some(ranges) = r.get_ranges() {
details.matched += ranges.len();
}
}
if let MatchResult::Rewrite(_) = r {
details.rewritten += 1;
Expand Down

0 comments on commit 709cacb

Please sign in to comment.