-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
count as context when already reached limit #1642
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -722,6 +722,14 @@ impl<'p, 's, M: Matcher, W: WriteColor> StandardSink<'p, 's, M, W> { | |
} | ||
self.after_context_remaining == 0 | ||
} | ||
|
||
fn match_more_than_limit(&self) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a small comment documenting this function? It would be useful to say, for example, that this always returns false if there is no limit. (And then copy the comment to the JSON printer.) |
||
let limit = match self.standard.config.max_matches { | ||
None => return false, | ||
Some(limit) => limit, | ||
}; | ||
self.match_count > limit | ||
} | ||
} | ||
|
||
impl<'p, 's, M: Matcher, W: WriteColor> Sink for StandardSink<'p, 's, M, W> { | ||
|
@@ -733,7 +741,12 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for StandardSink<'p, 's, M, W> { | |
mat: &SinkMatch, | ||
) -> Result<bool, io::Error> { | ||
self.match_count += 1; | ||
self.after_context_remaining = searcher.after_context() as u64; | ||
if self.match_more_than_limit() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment explaining this logic? (And then I guess copy the comment to the JSON printer as well.) It took me about 5 minutes of re-reading this code carefully to understand it. |
||
self.after_context_remaining = | ||
self.after_context_remaining.saturating_sub(1); | ||
} else { | ||
self.after_context_remaining = searcher.after_context() as u64; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also add a regression test at the bottom of this file? I know you added a regression integration test, but it would be good to cover it here too. |
||
|
||
self.record_matches(mat.bytes())?; | ||
self.replace(mat.bytes())?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a regression test at the bottom of this file so that we cover the JSON printer? It should be sufficient to mimic the existing tests where you only need to count the lines of output.