Repository navigation
feat: support range formatting - #40
Merged
Merged
Conversation
Formats only the lines of the instructions and comments a range touches, and upgrades dprint-core to 0.70.0.
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 (selection) formatting, following dprint/dprint-plugin-json#70 and the same feature in dprint-plugin-markdown, and upgrades dprint-core to 0.70.0.
Behaviour
format_text_rangewidens the range to the lines of the instructions and comments it touches and only replaces those lines. The text outside of them is left as it was, including its line endings and BOM.indentStages, the touched lines get the indentation they'd have when formatting the whole file.Implementation
generateis split intotop_level_nodesandgenerate_nodes, so only the touched top-level nodes are generated and printed, then spliced over their lines. Nothing is formatted and re-parsed to find the replacement. Whole-file formatting goes through the same two functions and is unchanged.Other changes
FileMatchingInfo.additive) and dprint-development 0.11.0 -> 0.12.1 (range markers in specs).cargo check --features tracing --tests, which failed on aparse_config_key_mapfunction that no longer exists.Tests
tests/specs/Range/: 23 spec files covering every instruction kind and form, comments, heredocs, the escape directive, lines that can't be parsed, and thelineWidth,indentStages,indentWidthandhealthcheckCmdNewLineoptions.src/format_range.rsfor what specs can't express: BOM, CRLF, lone carriage returns, range clamping, a missing final newline, andNoneresults.tests/range_test.rs: formats every cursor position and line selection of every spec's text (plus CRLF, BOM and trailing-text variants) and checks that the result formats to the same text as formatting the whole file, and that line endings and the BOM are kept. Takes about 8s in a debug build.Not addressed
On a file that already mixes line endings, the line breaks within a touched multi-line instruction are written with the file's dominant line ending.