chore(tools): Report regex capture text in fs_modify_file - #908
Merged
Conversation
When a regex pattern applied by `fs_modify_file` succeeds, the tool now reports the distinct text each match actually bound to, with occurrence counts, most frequent first. This is the one thing a regex author can't otherwise see: the pattern says what was intended and the diff says what resulted, but neither says what the engine bound. A quantifier that runs past its intended boundary (e.g. `[a-z-]+` swallowing part of the delimiter-separated text that follows it) now shows up as an unexpected captured string before anyone has to read a diff hunk. Literal patterns match themselves, so they report nothing new: a lone successful literal pattern still produces an empty report. Multi-pattern and failure reports gain a new section listing what each regex pattern matched, capped at 8 distinct entries per pattern to avoid flooding the output. Internally, `Content::replace_regexp` now returns a `Replacement` carrying the matched strings alongside the new content, and `PatternOutcome::Applied` carries a `matches: Vec<MatchTally>` field. Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a regex pattern applied by
fs_modify_filesucceeds, the tool now reports the distinct text each match actually bound to, with occurrence counts, most frequent first. This is the one thing a regex author can't otherwise see: the pattern says what was intended and the diff says what resulted, but neither says what the engine bound. A quantifier that runs past its intended boundary (e.g.[a-z-]+swallowing part of the delimiter-separated text that follows it) now shows up as an unexpected captured string before anyone has to read a diff hunk.Literal patterns match themselves, so they report nothing new: a lone successful literal pattern still produces an empty report. Multi-pattern and failure reports gain a new section listing what each regex pattern matched, capped at 8 distinct entries per pattern to avoid flooding the output.
Internally,
Content::replace_regexpnow returns aReplacementcarrying the matched strings alongside the new content, andPatternOutcome::Appliedcarries amatches: Vec<MatchTally>field.