Repository navigation
feat: support range formatting - #286
Merged
Merged
Conversation
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.
Adds range formatting, like dprint/dprint-plugin-json#70, and upgrades dprint-core to 0.70.0 (and dprint-development to 0.12.1).
format_text_rangefinds the blocks the range touches. It starts with the top-level blocks and goes into lists → items (their children and sub-lists) → block quote children. It formats the whole file, takes the formatted text of those blocks (from the start of the first block's line to the end of the last block's line) and puts it in place of the original. The result is reparsed to check that the blocks along the path are the same kinds, that the other blocks kept their exact text, and that the replaced blocks read back as formatted. For nested blocks, every sibling's line prefix (the container's indentation and>markers) must already be what the formatter writes. If a check fails, it tries the enclosing block, and so on out to formatting the whole file (ex. changing*items to-would split the list in two, so the whole list is formatted).\rline ending are formatted whole.I stress-tested it with about 25M range/config combinations over the spec files, the CommonMark examples, hand-written edge cases and generated documents, checking for panics, changes outside the touched blocks, the rendered HTML staying the same, and agreement with full formatting. Known minor cases left as is:
>lines at the edges of a block quote can stay after a partial format.