Skip to content

Commit 37b0ce8

Browse files
author
Nathan Hawes
authored
Merge pull request #26040 from nathawes/r51995648-placeholder-not-working-inside-pound-if-5.1
[5.1][SourceKit] Fix placeholder expansion not working inside #if
2 parents 183755e + f723c8e commit 37b0ce8

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

test/SourceKit/CodeExpand/code-expand.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,24 @@ singleExprClosureMultiArg(1) {
195195
// CHECK: withtrail {
196196
// CHECK-NEXT: <#code#>
197197
}
198+
199+
func active() {
200+
foo(<#T##value: Foo##Foo#>)
201+
// CHECK: foo(Foo)
202+
}
203+
func activeWithTrailing() {
204+
forEach(<#T##() -> ()#>)
205+
// CHECK: forEach {
206+
// CHECK-NEXT: <#code#>
207+
}
208+
#if false
209+
func inactive() {
210+
foo(<#T##value: Foo##Foo#>)
211+
// CHECK: foo(Foo)
212+
}
213+
func inactiveWithTrailing() {
214+
forEach(<#T##() -> ()#>)
215+
// CHECK: forEach {
216+
// CHECK-NEXT: <#code#>
217+
}
218+
#endif

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,22 @@ class PlaceholderExpansionScanner {
14091409
}
14101410
return { true, E };
14111411
}
1412+
1413+
bool walkToDeclPre(Decl *D) override {
1414+
if (auto *ICD = dyn_cast<IfConfigDecl>(D)) {
1415+
// The base walker assumes the content of active IfConfigDecl clauses
1416+
// has been injected into the parent context and will be walked there.
1417+
// This doesn't hold for pre-typechecked ASTs and we need to find
1418+
// placeholders in inactive clauses anyway, so walk them here.
1419+
for (auto Clause: ICD->getClauses()) {
1420+
for (auto Elem: Clause.Elements) {
1421+
Elem.walk(*this);
1422+
}
1423+
}
1424+
return false;
1425+
}
1426+
return true;
1427+
}
14121428
};
14131429

14141430
class ClosureTypeWalker: public ASTWalker {
@@ -1571,6 +1587,8 @@ class PlaceholderExpansionScanner {
15711587
return true;
15721588
}
15731589

1590+
bool shouldWalkInactiveConfigRegion() override { return true; }
1591+
15741592
Expr *findEnclosingCallArg(SourceFile &SF, SourceLoc SL) {
15751593
EnclosingCallAndArg = {nullptr, nullptr};
15761594
OuterExpr = nullptr;

0 commit comments

Comments
 (0)