Repository navigation
Reflow only the long strings in the code that formatting the ranges rewrites - #233
Merged
Merged
Conversation
This was referenced Nov 14, 2026
abashev
force-pushed
the
abashev/Range-reflow-in-process
branch
from
November 16, 2026 20:03
dae406a to
ed3bcf8
Compare
abashev
force-pushed
the
abashev/Range-reflow-inside
branch
from
November 16, 2026 20:03
2897566 to
2e3876f
Compare
abashev
force-pushed
the
abashev/Range-reflow-in-process
branch
from
November 16, 2026 20:05
ed3bcf8 to
33fe8c1
Compare
abashev
force-pushed
the
abashev/Range-reflow-inside
branch
from
November 16, 2026 20:05
2e3876f to
6e28b71
Compare
abashev
force-pushed
the
abashev/Range-reflow-in-process
branch
from
November 16, 2026 20:18
33fe8c1 to
94e5117
Compare
abashev
force-pushed
the
abashev/Range-reflow-inside
branch
from
November 16, 2026 20:22
6e28b71 to
3c36af2
Compare
--output-replacements, which IntelliJ IDEA and formatDiff run, and now the in-process service too, reflowed the whole file once a line in the ranges needed it, and long strings on lines nobody touched changed with it (#219). StringWrapper.wrap takes the ranges and reflows only the literals and text blocks that overlap them. Its passes format and replace text, so the ranges move along with each of them, growing to take in what a replacement rewrites. The ranges it gets are those of the code that formatting the given ranges rewrote, and they also decide whether to reflow at all; that check used to hold the ranges of the input against the lines of the formatted text. Without ranges nothing changes: the whole file is reflowed as before.
The tests of FormatterServicesTest and FormatDiffTest that reflow a long string on a changed line, with each of the in-process, bootstrapping and native formatters, get another long string, on a line that is not changed: it stays as it is.
abashev
force-pushed
the
abashev/Range-reflow-inside
branch
from
November 17, 2026 18:45
3c36af2 to
c799977
Compare
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.
Builds on #232; merge that first. Part of #219.
Formatting a part of a file reflows only the long strings in the code that formatting it rewrites. Before, once one line in the ranges needed reflowing, every long string in the file was reflowed, on lines nobody touched. This is what IntelliJ IDEA,
formatDiffand every other caller of--output-replacementsorFormatterService.getFormatReplacementsget, alike.StringWrapper.wrapwith ranges reflows only the literals and text blocks that overlap them, and moves the ranges along with each of its passes (moveRanges). Without ranges it runs as before.Formatter.getFormatAndReflowReplacementshands it the ranges of the code that formatting rewrote, which also decide whether to reflow at all; that check used to hold the ranges of the input against the formatted text.FormatterService.getFormatReplacementsformats the ranges and reflows the long strings in the code it rewrites; the imports, and the strings elsewhere, stay.What changes for users
Tests
StringWrapperTest: wrapping in ranges, and how ranges move with the replacements.FormatterServicesTest.reflows_the_long_string_of_the_rangeandFormatDiffTest.reflows_the_long_string_of_a_changed_line, from Reflow long strings in formatDiff on the JVM, as with the native binary #232, get a second long string on a line that is not changed: it stays, with the in-process, bootstrapping and native formatters. On the code of Reflow long strings in formatDiff on the JVM, as with the native binary #232 both fail with all three../gradlew checkpasses; 1,421 tests in:open-java-format. JDK 25 and JDK 28 (28+23-ea)::open-java-format:testpasses.-PnativeImage=true(macOS aarch64, GraalVM 25)::open-java-format-jdk-bootstrap:test11 of 11,:gradle-open-java-format:test156 of 156.