Skip to content

Commit 046c914

Browse files
committed
[CodeCompletion] Use getBodySourceRange() instead of getSourceRange()
To check if the completion is happening in the AFD body. Otherwise, local variables are sometimes not suggested because the body and its range is from another file. rdar://problem/58175106
1 parent 746b58e commit 046c914

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,8 @@ static void lookupVisibleDeclsImpl(VisibleDeclConsumer &Consumer,
10881088
// FIXME: when we can parse and typecheck the function body partially for
10891089
// code completion, AFD->getBody() check can be removed.
10901090
if (Loc.isValid() &&
1091-
AFD->getSourceRange().isValid() &&
1092-
SM.rangeContainsTokenLoc(AFD->getSourceRange(), Loc) &&
1091+
AFD->getBodySourceRange().isValid() &&
1092+
SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc) &&
10931093
AFD->getBody()) {
10941094
namelookup::FindLocalVal(SM, Loc, Consumer).visit(AFD->getBody());
10951095
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
func test() {
2+
var localVar = 1
3+
4+
var afterVar = 1
5+
}
6+
7+
// RUN: %sourcekitd-test \
8+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=3:1 %s -- %s == \
9+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=3:1 %s -- %s == \
10+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=3:1 %s -- %s == \
11+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=3:1 %s -- %s == \
12+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=3:1 %s -- %s | %FileCheck %s
13+
14+
// CHECK-NOT: key.name: "localVar"
15+
// CHECK-NOT: key.name: "afterVar"
16+
// CHECK: key.name: "localVar"
17+
// CHECK-NOT: key.name: "afterVar"
18+
// CHECK: key.name: "localVar"
19+
// CHECK-NOT: key.name: "afterVar"
20+
// CHECK: key.name: "localVar"
21+
// CHECK-NOT: key.name: "afterVar"
22+
// CHECK: key.name: "localVar"
23+
// CHECK-NOT: key.name: "afterVar"
24+
// CHECK: key.name: "localVar"
25+
// CHECK-NOT: key.name: "localVar"
26+
// CHECK-NOT: key.name: "afterVar"

0 commit comments

Comments
 (0)