Skip to content

Commit 72ce3f9

Browse files
committed
[SourceKit] Handle macro arguments in placeholder expansion
Allow macro argument placeholders to expand into trailing closures. rdar://150550747
1 parent ef74028 commit 72ce3f9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/SourceKit/CodeExpand/code-expand.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,22 @@ expandClosureWithInternalParameterNames {
273273
// CHECK: withtrail { a, b in
274274
// CHECK-NEXT: <#code#>
275275
}
276+
277+
func expandMacro() {
278+
#foo(<#T##() -> Int#>)
279+
// CHECK: #foo {
280+
// CHECK-NEXT: <#code#>
281+
// CHECK-NEXT: }
282+
283+
#foo(bar: <#T##() -> ()#>)
284+
// CHECK: #foo {
285+
// CHECK-NEXT: <#code#>
286+
// CHECK-NEXT: }
287+
288+
#foo(bar: <#T##() -> Int#>, baz: <#T##() -> ()#>)
289+
// CHECK: #foo {
290+
// CHECK-NEXT: <#code#>
291+
// CHECK-NEXT: } baz: {
292+
// CHECK-NEXT: <#code#>
293+
// CHECK-NEXT: }
294+
}

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,9 @@ class PlaceholderExpansionScanner {
16901690
if (auto *CE = dyn_cast<CallExpr>(E)) {
16911691
// Call expression can have argument.
16921692
Args = CE->getArgs();
1693+
} else if (auto *ME = dyn_cast<MacroExpansionExpr>(E)) {
1694+
// Macros can have arguments.
1695+
Args = ME->getArgs();
16931696
}
16941697
if (!Args)
16951698
return false;

0 commit comments

Comments
 (0)