Skip to content

Commit dd6046b

Browse files
committed
[CodeCompletion] Stop recording interface hash when searching CC token
1 parent 6653172 commit dd6046b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lib/Parse/ParseIfConfig.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ ParserResult<IfConfigDecl> Parser::parseIfConfig(
614614
bool hasCCToken = false;
615615
if (SourceMgr.hasCodeCompletionBuffer() &&
616616
SourceMgr.getCodeCompletionBufferID() == L->getBufferID()) {
617+
llvm::SaveAndRestore<Optional<llvm::MD5>> H(CurrentTokenHash, None);
617618
BacktrackingScope backtrack(*this);
618619
auto startLoc = Tok.getLoc();
619620
skipSingle();
@@ -676,6 +677,7 @@ ParserResult<IfConfigDecl> Parser::parseIfConfig(
676677

677678
// Treat the region containing code completion token as "active".
678679
if (hasCCToken && !foundActive) {
680+
llvm::SaveAndRestore<Optional<llvm::MD5>> H(CurrentTokenHash, None);
679681
BacktrackingScope backtrack(*this);
680682
auto startLoc = Tok.getLoc();
681683
skipUntilConditionalBlockClose();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
struct MyStruct {
2+
init() {}
3+
var value: Int = 1
4+
}
5+
6+
func foo(arg: MyStruct) {
7+
#if true
8+
_ = arg./*8:11*/
9+
#else
10+
_ = arg./*10:11*/
11+
#endif
12+
}
13+
14+
struct TestStruct {
15+
#if true
16+
func testActive(arg: MyStruct) {
17+
_ = arg./*17:13*/
18+
}
19+
#else
20+
func testInactive(arg: MyStruct) {
21+
_ = arg./*21:13*/
22+
}
23+
#endif
24+
}
25+
26+
// Test that (1) fast completion happens even in inactive #if blocks, and
27+
// (2) #if in toplevel decls invalidate cached ASTContext
28+
29+
// RUN: %sourcekitd-test \
30+
// RUN: -req=complete -pos=8:11 %s -- %s -parse-as-library == \
31+
// RUN: -req=complete -pos=10:11 %s -- %s -parse-as-library == \
32+
// RUN: -req=complete -pos=17:13 %s -- %s -parse-as-library == \
33+
// RUN: -req=complete -pos=21:13 %s -- %s -parse-as-library \
34+
// RUN: | %FileCheck %s --check-prefix=RESULT
35+
36+
// RESULT-LABEL: key.results: [
37+
// RESULT-DAG: key.description: "value"
38+
// RESULT: ]
39+
// RESULT-NOT: key.reusingastcontext: 1
40+
41+
// RESULT-LABEL: key.results: [
42+
// RESULT-DAG: key.description: "value"
43+
// RESULT: ]
44+
// RESULT: key.reusingastcontext: 1
45+
46+
// RESULT-LABEL: key.results: [
47+
// RESULT-DAG: key.description: "value"
48+
// RESULT: ]
49+
// RESULT: key.reusingastcontext: 1
50+
51+
// RESULT-LABEL: key.results: [
52+
// RESULT-DAG: key.description: "value"
53+
// RESULT: ]
54+
// RESULT-NOT: key.reusingastcontext: 1

0 commit comments

Comments
 (0)