Skip to content

[5.3][SourceKit/CodeFormat] Fix multi-line array literal elements not indenting relative to their first line. #32583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Jun 27, 2020

Cherry-pick of #32582 for 5.3

  • Explanation:
    Multi-line array literal elements were not indenting relative to their first line as they did before the indentation overhaul. Each item in an array literal wasn't being reported as an indent context, so we under-indented their continuation lines as in the example below:

    doStuffWithList([
        firstItem
        .map {$0}            // This line should be indented further.
        .append(\.foo),      // So should this one
        secondItem
        .filter {$0 > 5}.    // and this one.
    ])
    

    This change makes them an indent context giving the behavior below:

    doStuffWithList([
        firstItem
            .map {$0}
            .append(\.foo),
        secondItem
            .filter {$0 > 5}
    ])
    
  • Scope: Affects the indentation of all multi-line expressions expression within array literals.

  • Risk: Low. It's a small targeted fix that only affects sourcekitd's CodeFormat request. It has no impact on sourcekitd's other requests or the compiler.

  • Origination: Since the indentation overhaul in 5.3.

  • Testing: Added a regression test for this case and all existing tests pass.

  • Reviewer: Ben Langmuir (@benlangmuir) on the master PR

Resolves rdar://problem/64834040

…nting relative to their first line.

doStuffWithList([
    firstItem
    .map { $0 }       // This line should be indented further.
    .append(\.foo),   // And so should this one.
    secondItem
])

Resolves rdar://problem/64834040
@nathawes nathawes added the r5.3 label Jun 27, 2020
@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes marked this pull request as ready for review June 29, 2020 16:50
@nathawes nathawes requested a review from a team as a code owner June 29, 2020 16:50
@nathawes nathawes requested a review from akyrtzi June 29, 2020 16:50
@nathawes
Copy link
Contributor Author

@swift-ci please nominate

@akyrtzi akyrtzi merged commit 829238c into swiftlang:release/5.3 Jun 29, 2020
@nathawes nathawes deleted the array-literal-sub-expr-indentation-fix-5.3 branch June 29, 2020 16:56
@AnthonyLatsis AnthonyLatsis added swift 5.3 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants