Skip to content

Add buildFinalResult to CodeBlockItemListBuilder to ensure newline between expressions #2829

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

mateusrodriguesxyz
Copy link
Contributor

This ensures that the following usage of CodeBlockItemListBuilder produces a valid block where expressions are separated by newlines:

CodeBlockItemListSyntax {
    "let a = 1"
    "let b = 2"
    "let c = 3"
}

Something similar it's already done for comma separated lists here.

I've also modified the collapse function to avoid adding unnecessary separators to a macro expansion. This change is important because if someone uses CodeBlockItemListBuilder as in testDontAddIndentationWhenCollapsingBody, they might be surprised by unexpected empty lines if collapse adds separator unconditionally.

func f() {
#sourceLocation(file: "test.swift", line: 3)

        let x: Int = 1

#sourceLocation()
}

@mateusrodriguesxyz mateusrodriguesxyz force-pushed the code-block-builder-add-build-final-result branch from 242817b to 8f477f3 Compare September 2, 2024 19:22
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mateusrodriguesxyz. Could you add a test case for this?

@mateusrodriguesxyz mateusrodriguesxyz force-pushed the code-block-builder-add-build-final-result branch from 8f477f3 to 357c104 Compare September 11, 2024 17:39
@mateusrodriguesxyz
Copy link
Contributor Author

@ahoppen done!

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nitpick, otherwise looks good to me.

@mateusrodriguesxyz mateusrodriguesxyz force-pushed the code-block-builder-add-build-final-result branch from 357c104 to 83244d4 Compare September 13, 2024 20:50
@ahoppen
Copy link
Member

ahoppen commented Sep 19, 2024

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge September 19, 2024 00:23
@ahoppen
Copy link
Member

ahoppen commented Sep 20, 2024

Not entirely sure why but there seems to be a build failure on Linux only. 🤔 Could you take a look at it @mateusrodriguesxyz?

auto-merge was automatically disabled September 20, 2024 19:38

Head branch was pushed to by a user without write access

@mateusrodriguesxyz mateusrodriguesxyz force-pushed the code-block-builder-add-build-final-result branch from 83244d4 to 95f5aa6 Compare September 20, 2024 19:38
@mateusrodriguesxyz
Copy link
Contributor Author

Not entirely sure why but there seems to be a build failure on Linux only.

It's because I used SE-0380 which it's not available in Swift 5.8 😅 It's fixed now. Could you test again please? @ahoppen

@ahoppen
Copy link
Member

ahoppen commented Sep 20, 2024

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge September 20, 2024 20:36
@ahoppen
Copy link
Member

ahoppen commented Sep 22, 2024

@swift-ci Please test

@ahoppen ahoppen merged commit a32bdbf into swiftlang:main Sep 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants