Skip to content

adjust Indentation Of Freestanding Macro #2493

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

Merged

Conversation

vinu-vanjari
Copy link
Contributor

@vinu-vanjari vinu-vanjari commented Feb 12, 2024

Resolves #2473


Summary:

  • added private function adjustIndentationOfFreestandingMacro which extracts the same indentation logic as before, plus removes first line indentation if macro is in middle of any line. This is required as line indentation does not make sense if macro is not present at the beginning of the line.

    • eg. print(#function) used to produce print( "f(a:_:c:)") with extra indentation after (. Now it should produce print("f(a:_:c:)")
  • corrected existing unit tests + added similar tests for multi line macro expansion so that we make sure indentation is correct on large macros as well even if they are used in middle of the line


Update:

  • adjustIndentationOfFreestandingMacro adds appropriate indentation to expanded code. Then removes indentation of first line of expanded code (if any). Then adds exact same trivia as # macro, including it's original indentation.
  • Hence removing extra indentation from the expanded code itself and not from leading trivia of # macro node
  • Added more test cases with comments with the # macro which were failing earlier

@vinu-vanjari vinu-vanjari force-pushed the macro-adjustIndentationOfFreestandingMacro branch from 7c19b5b to 32c6662 Compare February 12, 2024 16:03
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.

Thanks for fixing this @vinu-vanjari!

@vinu-vanjari vinu-vanjari requested a review from ahoppen February 14, 2024 16:09
@vinu-vanjari vinu-vanjari requested a review from ahoppen February 16, 2024 06:41
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.

Nice. Thanks for adding the comment.

@ahoppen
Copy link
Member

ahoppen commented Feb 19, 2024

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge February 19, 2024 18:58
@ahoppen
Copy link
Member

ahoppen commented Feb 20, 2024

@swift-ci Please test

auto-merge was automatically disabled February 20, 2024 04:20

Head branch was pushed to by a user without write access

@vinu-vanjari
Copy link
Contributor Author

@ahoppen, sorry I missed formatting in my latest commit. Just fixed it now. 🙏🏼

@ahoppen
Copy link
Member

ahoppen commented Feb 20, 2024

No worries, let’s try again.

@swift-ci Please test

@vinu-vanjari
Copy link
Contributor Author

Kindly help, I am not able to understand root cause of the CI failure.

As per console logs,

/Users/ec2-user/jenkins/workspace/swift-syntax-PR-macOS/branch-main/swift-syntax/Examples/Tests/MacroExamples/Implementation/ComplexMacros/DictionaryIndirectionMacroTests.swift:13:8: error: no such module 'MacroExamplesImplementation'
import MacroExamplesImplementation
       ^
note: module 'MacroExamplesImplementation' is a macro, and cannot be imported by tests and other targets
error: fatalError
Error: Command failed with non-zero exit code 1:

but i am not sure if my changes affected MacroExamplesImplementation

@Matejkob
Copy link
Contributor

Kindly help, I am not able to understand root cause of the CI failure.

As per console logs,

/Users/ec2-user/jenkins/workspace/swift-syntax-PR-macOS/branch-main/swift-syntax/Examples/Tests/MacroExamples/Implementation/ComplexMacros/DictionaryIndirectionMacroTests.swift:13:8: error: no such module 'MacroExamplesImplementation'
import MacroExamplesImplementation
       ^
note: module 'MacroExamplesImplementation' is a macro, and cannot be imported by tests and other targets
error: fatalError
Error: Command failed with non-zero exit code 1:

but i am not sure if my changes affected MacroExamplesImplementation

The CI error is not related to your changes. It should be fix after merging this PR: swiftlang/swift-package-manager#7349

@MaxDesiatov
Copy link
Contributor

swiftlang/swift-package-manager#7350 instead of swiftlang/swift-package-manager#7349 should've fixed CI issues, as it clearly fixes the test build error for me locally. I'm currently investigating why the error persists on CI, as I hope we can avoid merging the revert and get this fixed properly.

@Matejkob
Copy link
Contributor

apple/swift-package-manager#7350 instead of apple/swift-package-manager#7349 should've fixed CI issues, as it clearly fixes the test build error for me locally. I'm currently investigating why the error persists on CI, as I hope we can avoid merging the revert and get this fixed properly.

Oh, sorry for the misleading info, didn't go throw the new conversation in the PR since yesterday

@MaxDesiatov
Copy link
Contributor

@swift-ci clean test

@MaxDesiatov
Copy link
Contributor

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.

Incorrect indentation added to macro that doesn’t start on a new line
4 participants