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
git diff
was replaced withdifflib.SequenceMatcher
in #11, I failed to also re-implement "context expansion". The equivalent ofgit diff -U<number-of-context-lines>
is now properly implemented indiff_and_get_opcodes()
again. Additionally, the number of extra context lines can no longer grow beyond the number of lines in the processed file.What context expansion does is:
In case the AST of the original edited file doesn't match with the AST of the partially reformatted one, darker considers one more line before and after every user-edited chunk as part of the chunk. This expansion is repeated one line at a time until the ASTs match.
Context expansion helps is rare cases of two nearby chunks of Black reformatting separated by intact lines. Sometimes applying only one of those nearby chunks causes the AST to change, and context expansion will eventually cause them to be applied together.