swiftlang / swiftlang/swift-syntax

ExpressionMacro trailing closure inherits code's original indentation

Open
#2,126 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
3.7k
Forks
553
Avg merge
5d 13h
Merged PRs (30d)
16

Description

### Description

If macro is nested in some closure, its trailing closure preserves the original code indentation. So if I build `FunctionCallExprSyntax` with trailing closure that takes statements from the original trailing closure, the new statements are incorrectly indented.

This probably applies as well to closure as last argument.

Is there any manual way to trim the statements to decrease the indent?

### Steps to Reproduce

```swift
assertMacroExpansion(
#"""
VStack {
#SomeMacro(arg1) { output in
EmptyView()
}
}
"""#,
expandedSource: #"""
VStack {
SomeWrapper(arg1) { output in
EmptyView()
}
}
"""#,
macros: testMacros
)
```
The code above incorrectly expands to:
```swift
#"""
VStack {
SomeWrapper(arg1) { output in
EmptyView()
}
}
"""#
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.