Skip to content

Commit

Permalink
feat(search): add matches number to summary (#3747)
Browse files Browse the repository at this point in the history
  • Loading branch information
BackupMiles committed Sep 2, 2024
1 parent 61728c9 commit ac0408f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/biome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub(crate) enum FileStatus {
Unchanged,
/// While handling the file, something happened
Message(Message),
/// A match was found while searching a file
SearchResult(Message),
/// File ignored, it should not be count as "handled"
Ignored,
/// Files that belong to other tools and shouldn't be touched
Expand Down
8 changes: 7 additions & 1 deletion crates/biome_cli/src/execute/process_file/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(crate) fn search_with_guard<'ctx>(

let input = workspace_file.input()?;
let file_name = workspace_file.path.display().to_string();
let matches_len = result.matches.len();

let search_results = Message::Diagnostics {
name: file_name,
Expand All @@ -42,7 +43,12 @@ pub(crate) fn search_with_guard<'ctx>(
.collect(),
skipped_diagnostics: 0,
};
Ok(FileStatus::Message(search_results))

if matches_len > 0 {
Ok(FileStatus::SearchResult(search_results))
} else {
Ok(FileStatus::Message(search_results))
}
},
)
}
14 changes: 14 additions & 0 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub(crate) fn traverse(

let changed = AtomicUsize::new(0);
let unchanged = AtomicUsize::new(0);
let matches = AtomicUsize::new(0);
let skipped = AtomicUsize::new(0);

let fs = &*session.app.fs;
Expand Down Expand Up @@ -107,6 +108,7 @@ pub(crate) fn traverse(
workspace,
execution,
interner,
matches: &matches,
changed: &changed,
unchanged: &unchanged,
skipped: &skipped,
Expand All @@ -132,6 +134,7 @@ pub(crate) fn traverse(
let warnings = printer.warnings();
let changed = changed.load(Ordering::Relaxed);
let unchanged = unchanged.load(Ordering::Relaxed);
let matches = matches.load(Ordering::Relaxed);
let skipped = skipped.load(Ordering::Relaxed);
let suggested_fixes_skipped = printer.skipped_fixes();
let diagnostics_not_printed = printer.not_printed_diagnostics();
Expand All @@ -141,6 +144,7 @@ pub(crate) fn traverse(
unchanged,
duration,
errors,
matches,
warnings,
skipped,
suggested_fixes_skipped,
Expand Down Expand Up @@ -547,6 +551,8 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
changed: &'ctx AtomicUsize,
/// Shared atomic counter storing the number of unchanged files
unchanged: &'ctx AtomicUsize,
/// Shared atomic counter storing the number of unchanged files
matches: &'ctx AtomicUsize,
/// Shared atomic counter storing the number of skipped files
skipped: &'ctx AtomicUsize,
/// Channel sending messages to the display thread
Expand All @@ -568,6 +574,9 @@ impl<'ctx, 'app> TraversalOptions<'ctx, 'app> {
pub(crate) fn increment_unchanged(&self) {
self.unchanged.fetch_add(1, Ordering::Relaxed);
}
pub(crate) fn increment_matches(&self) {
self.matches.fetch_add(1, Ordering::Relaxed);
}

/// Send a message to the display thread
pub(crate) fn push_message(&self, msg: impl Into<Message>) {
Expand Down Expand Up @@ -691,6 +700,11 @@ fn handle_file(ctx: &TraversalOptions, path: &BiomePath) {
Ok(Ok(FileStatus::Unchanged)) => {
ctx.increment_unchanged();
}
Ok(Ok(FileStatus::SearchResult(msg))) => {
ctx.increment_unchanged();
ctx.increment_matches();
ctx.push_message(msg);
}
Ok(Ok(FileStatus::Message(msg))) => {
ctx.increment_unchanged();
ctx.push_message(msg);
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/reporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct DiagnosticsPayload {
pub struct TraversalSummary {
pub changed: usize,
pub unchanged: usize,
pub matches: usize,
// We skip it during testing because the time isn't predictable
#[cfg_attr(debug_assertions, serde(skip))]
pub duration: Duration,
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_cli/src/reporter/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ impl<'a> fmt::Display for ConsoleTraversalSummary<'a> {
fmt.write_markup(markup!("\n"<Warn>"Found "{self.1.warnings}" warnings."</Warn>))?;
}
}

if let TraversalMode::Search { .. } = self.0 {
fmt.write_markup(markup!(" "<Info>"Found "{self.1.matches}" matches."</Info>))?
};
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ The --json option is unstable/experimental and its output might change between p
```

```block
{"summary":{"changed":1,"unchanged":0,"errors":0,"warnings":0,"skipped":0,"suggestedFixesSkipped":0,"diagnosticsNotPrinted":0},"diagnostics":[],"command":"check"}
{"summary":{"changed":1,"unchanged":0,"matches":0,"errors":0,"warnings":0,"skipped":0,"suggestedFixesSkipped":0,"diagnosticsNotPrinted":0},"diagnostics":[],"command":"check"}
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The --json option is unstable/experimental and its output might change between p
"summary": {
"changed": 1,
"unchanged": 0,
"matches": 0,
"errors": 0,
"warnings": 0,
"skipped": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ The --json option is unstable/experimental and its output might change between p
```

```block
{"summary":{"changed":0,"unchanged":1,"errors":1,"warnings":0,"skipped":0,"suggestedFixesSkipped":0,"diagnosticsNotPrinted":0},"diagnostics":[{"category":"format","severity":"error","description":"Formatter would have printed the following content:","message":[{"elements":[],"content":"Formatter would have printed the following content:"}],"advices":{"advices":[{"diff":{"dictionary":" statement();\n","ops":[{"diffOp":{"delete":{"range":[0,2]}}},{"diffOp":{"equal":{"range":[2,12]}}},{"diffOp":{"delete":{"range":[0,2]}}},{"diffOp":{"equal":{"range":[12,13]}}},{"diffOp":{"delete":{"range":[0,2]}}},{"diffOp":{"insert":{"range":[13,15]}}}]}}]},"verboseAdvices":{"advices":[]},"location":{"path":{"file":"format.js"},"span":null,"sourceCode":" statement( ) "},"tags":[],"source":null}],"command":"format"}
{"summary":{"changed":0,"unchanged":1,"matches":0,"errors":1,"warnings":0,"skipped":0,"suggestedFixesSkipped":0,"diagnosticsNotPrinted":0},"diagnostics":[{"category":"format","severity":"error","description":"Formatter would have printed the following content:","message":[{"elements":[],"content":"Formatter would have printed the following content:"}],"advices":{"advices":[{"diff":{"dictionary":" statement();\n","ops":[{"diffOp":{"delete":{"range":[0,2]}}},{"diffOp":{"equal":{"range":[2,12]}}},{"diffOp":{"delete":{"range":[0,2]}}},{"diffOp":{"equal":{"range":[12,13]}}},{"diffOp":{"delete":{"range":[0,2]}}},{"diffOp":{"insert":{"range":[13,15]}}}]}}]},"verboseAdvices":{"advices":[]},"location":{"path":{"file":"format.js"},"span":null,"sourceCode":" statement( ) "},"tags":[],"source":null}],"command":"format"}
```
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The --json option is unstable/experimental and its output might change between p
"summary": {
"changed": 0,
"unchanged": 1,
"matches": 0,
"errors": 1,
"warnings": 0,
"skipped": 0,
Expand Down

0 comments on commit ac0408f

Please sign in to comment.