-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
cc37b44
to
1d6049e
Compare
@BurntSushi can this be merged |
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.
Thanks for taking a stab at this! I think I buy the fix, but would like to see this polished up a bit before merging.
} else { | ||
self.after_context_remaining = searcher.after_context() as u64; | ||
} | ||
|
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.
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 comment
The 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.
@@ -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 comment
The 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.
@@ -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 comment
The 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.)
it will fix #1380, and it is a breaking change