[5.3][SourceKit/CodeFormat] Fix var/let declaration continuation lines appearing over-indented. #31945
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.
Cherry-pick of #31941 for 5.3
Explanation:
The indentation of pattern binding decls was changed in 5.3 to improve their readability when they include multiple entries by column-aligning the entries and indenting their continuation lines relative to that column too. This change made pattern binding decls with a single entry that continued onto a second line seem over-indented, though, both relative to their surrounding code and to how they were treated in the 5.2 release, and single-entry pattern binding decls are used far more commonly than multiple-entry ones. This change fixes the over-indentation issue by not column-aligning the entries if any entry starts on the same line as the var/let and continues onto a later line. For example:
Using this rule, as opposed to handling single and multi-entry PBDs differently, ensures that the as-typed-out indentation (where it's unclear how many entries the user intends to write) matches the selected-and-reindented indentation for multi-entry pattern binding decls.
Scope of issue: The over-indentation affects all multi-line var/let declarations in Swift source files, and I expect many users would consider it a regression relative to the 5.2 behavior.
Origination: Since the indentation implementation was overhauled in [SourceKit/CodeFormat] Re-work and improve the indentation implementation #30187
Risk: Low. This only affects sourcekitd (not the compiler), and specifically only its CodeFormat request. It is a targeted fix that only affects the indentation within pattern binding declarations (var/let declarations).
Testing: Updated and added regression tests for this change, regression tests pass, and I manually tested the changes in Xcode.
Reviewer: @benlangmuir (on the master branch PR)
Resolves rdar://problem/63309288