Skip to content

Commit

Permalink
fix(search): fix num results (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Sep 9, 2024
1 parent b93a266 commit bdf8547
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(crate) enum FileStatus {
/// While handling the file, something happened
Message(Message),
/// A match was found while searching a file
SearchResult(Message),
SearchResult(usize, Message),
/// File ignored, it should not be count as "handled"
Ignored,
/// Files that belong to other tools and shouldn't be touched
Expand Down
6 changes: 1 addition & 5 deletions crates/biome_cli/src/execute/process_file/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ pub(crate) fn search_with_guard<'ctx>(
skipped_diagnostics: 0,
};

if matches_len > 0 {
Ok(FileStatus::SearchResult(search_results))
} else {
Ok(FileStatus::Message(search_results))
}
Ok(FileStatus::SearchResult(matches_len, search_results))
},
)
}
9 changes: 5 additions & 4 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +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);

pub(crate) fn increment_matches(&self, num_matches: usize) {
self.matches.fetch_add(num_matches, Ordering::Relaxed);
}

/// Send a message to the display thread
Expand Down Expand Up @@ -700,9 +701,9 @@ fn handle_file(ctx: &TraversalOptions, path: &BiomePath) {
Ok(Ok(FileStatus::Unchanged)) => {
ctx.increment_unchanged();
}
Ok(Ok(FileStatus::SearchResult(msg))) => {
Ok(Ok(FileStatus::SearchResult(num_matches, msg))) => {
ctx.increment_unchanged();
ctx.increment_matches();
ctx.increment_matches(num_matches);
ctx.push_message(msg);
}
Ok(Ok(FileStatus::Message(msg))) => {
Expand Down
6 changes: 5 additions & 1 deletion crates/biome_cli/src/reporter/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ impl<'a> fmt::Display for ConsoleTraversalSummary<'a> {
}

if let TraversalMode::Search { .. } = self.0 {
fmt.write_markup(markup!(" "<Info>"Found "{self.1.matches}" matches."</Info>))?
if self.1.matches == 1 {
fmt.write_markup(markup!(" "<Info>"Found "{self.1.matches}" match."</Info>))?
} else {
fmt.write_markup(markup!(" "<Info>"Found "{self.1.matches}" matches."</Info>))?
};
};
Ok(())
}
Expand Down

0 comments on commit bdf8547

Please sign in to comment.