Skip to content

Commit d7b65e6

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 (cherry picked from commit 046c914)
1 parent b6b943e commit d7b65e6

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
@@ -1089,8 +1089,8 @@ static void lookupVisibleDeclsImpl(VisibleDeclConsumer &Consumer,
10891089
// FIXME: when we can parse and typecheck the function body partially for
10901090
// code completion, AFD->getBody() check can be removed.
10911091
if (Loc.isValid() &&
1092-
AFD->getSourceRange().isValid() &&
1093-
SM.rangeContainsTokenLoc(AFD->getSourceRange(), Loc) &&
1092+
AFD->getBodySourceRange().isValid() &&
1093+
SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc) &&
10941094
AFD->getBody()) {
10951095
namelookup::FindLocalVal(SM, Loc, Consumer).visit(AFD->getBody());
10961096
}
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)