Skip to content

Commit 2f4dcf3

Browse files
committed
[CodeCompletion] Fix issue in dependency checking for the editing file
'SM.getCodeCompletionBufferID()' returns the buffer ID of the previous code completion. 'CI.getCodeCompletionFile()->getBufferID()' always returns the original source buffer ID of the current file in the main module. The latter is needed for excluding buffer ID for dependency checking. rdar://problem/66301353
1 parent 5919697 commit 2f4dcf3

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

lib/IDE/CompletionInstance.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,20 @@ bool CompletionInstance::performCachedOperationIfPossible(
295295

296296
auto &CI = *CachedCI;
297297
auto *oldSF = CI.getCodeCompletionFile();
298+
assert(oldSF->getBufferID());
298299

299300
auto *oldState = oldSF->getDelayedParserState();
300301
assert(oldState->hasCodeCompletionDelayedDeclState());
301302
auto &oldInfo = oldState->getCodeCompletionDelayedDeclState();
302303

303304
auto &SM = CI.getSourceMgr();
304305
auto bufferName = completionBuffer->getBufferIdentifier();
305-
if (SM.getIdentifierForBuffer(SM.getCodeCompletionBufferID()) != bufferName)
306+
if (SM.getIdentifierForBuffer(*oldSF->getBufferID()) != bufferName)
306307
return false;
307308

308309
if (shouldCheckDependencies()) {
309310
if (areAnyDependentFilesInvalidated(
310-
CI, *FileSystem, SM.getCodeCompletionBufferID(),
311+
CI, *FileSystem, *oldSF->getBufferID(),
311312
DependencyCheckedTimestamp, InMemoryDependencyHash))
312313
return false;
313314
DependencyCheckedTimestamp = std::chrono::system_clock::now();
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// BEGIN State1.swift
2+
import ClangFW
3+
import SwiftFW
4+
5+
func foo(val: MyStruct) {
6+
/*HERE*/
7+
}
8+
9+
// BEGIN State2.swift
10+
import ClangFW
11+
import SwiftFW
12+
13+
func foo(val: MyStruct) {
14+
val./*HERE*/
15+
}
16+
17+
// BEGIN DUMMY.swift
18+
19+
// Checks that editing and saving the current file doesn't affect dependency checking.
20+
// REQUIRES: shell
21+
22+
// RUN: %empty-directory(%t)
23+
// RUN: %empty-directory(%t/Frameworks)
24+
// RUN: %empty-directory(%t/MyProject)
25+
26+
// RUN: %{python} %utils/split_file.py -o %t %s
27+
28+
// RUN: COMPILER_ARGS=( \
29+
// RUN: -target %target-triple \
30+
// RUN: -module-name MyProject \
31+
// RUN: -F %t/Frameworks \
32+
// RUN: -I %t/MyProject \
33+
// RUN: -import-objc-header %t/MyProject/Bridging.h \
34+
// RUN: %t/MyProject/Library.swift \
35+
// RUN: %t/test.swift \
36+
// RUN: )
37+
// RUN: INPUT_DIR=%S/Inputs/checkdeps
38+
// RUN: DEPCHECK_INTERVAL=1
39+
// RUN: SLEEP_TIME=2
40+
41+
// RUN: cp -R $INPUT_DIR/MyProject %t/
42+
// RUN: cp -R $INPUT_DIR/ClangFW.framework %t/Frameworks/
43+
// RUN: %empty-directory(%t/Frameworks/SwiftFW.framework/Modules/SwiftFW.swiftmodule)
44+
// RUN: %target-swift-frontend -emit-module -module-name SwiftFW -o %t/Frameworks/SwiftFW.framework/Modules/SwiftFW.swiftmodule/%target-swiftmodule-name $INPUT_DIR/SwiftFW_src/Funcs.swift
45+
46+
// RUN: cp %t/State1.swift %t/test.swift
47+
48+
// RUN: %sourcekitd-test \
49+
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
50+
51+
// RUN: -shell -- echo "### Initial" == \
52+
// RUN: -req=complete -pos=5:4 %t/test.swift -- ${COMPILER_ARGS[@]} == \
53+
54+
// RUN: -shell -- sleep ${SLEEP_TIME} == \
55+
// RUN: -shell -- echo "### Modify own file - 1" == \
56+
// RUN: -shell -- cp %t/State2.swift %t/test.swift == \
57+
// RUN: -req=complete -pos=5:9 %t/test.swift -- ${COMPILER_ARGS[@]} == \
58+
59+
// RUN: -shell -- sleep ${SLEEP_TIME} == \
60+
// RUN: -shell -- echo "### Modify own file - 2" == \
61+
// RUN: -shell -- cp %t/State1.swift %t/test.swift == \
62+
// RUN: -req=complete -pos=5:4 %t/test.swift -- ${COMPILER_ARGS[@]} == \
63+
64+
// RUN: -shell -- sleep ${SLEEP_TIME} == \
65+
// RUN: -shell -- echo "### Modify own file - 3" == \
66+
// RUN: -shell -- cp %t/State2.swift %t/test.swift == \
67+
// RUN: -req=complete -pos=5:9 %t/test.swift -- ${COMPILER_ARGS[@]} \
68+
// RUN: | %FileCheck %s
69+
70+
// CHECK-LABEL: ### Initial
71+
// CHECK: key.results: [
72+
// CHECK-DAG: key.description: "clangFWFunc()"
73+
// CHECK-DAG: key.description: "swiftFWFunc()"
74+
// CHECK-DAG: key.description: "localClangFunc()"
75+
// CHECK-DAG: key.description: "localSwiftFunc()"
76+
// CHECK: ]
77+
// CHECK-NOT: key.reusingastcontext: 1
78+
79+
// CHECK-LABEL: ### Modify own file - 1
80+
// CHECK: key.results: [
81+
// CHECK-DAG: key.description: "myStructMethod()"
82+
// CHECK-DAG: key.description: "self"
83+
// CHECK: ]
84+
// CHECK: key.reusingastcontext: 1
85+
86+
// CHECK-LABEL: ### Modify own file - 2
87+
// CHECK: key.results: [
88+
// CHECK-DAG: key.description: "clangFWFunc()"
89+
// CHECK-DAG: key.description: "swiftFWFunc()"
90+
// CHECK-DAG: key.description: "localClangFunc()"
91+
// CHECK-DAG: key.description: "localSwiftFunc()"
92+
// CHECK: ]
93+
// CHECK: key.reusingastcontext: 1
94+
95+
// CHECK-LABEL: ### Modify own file - 3
96+
// CHECK: key.results: [
97+
// CHECK-DAG: key.description: "myStructMethod()"
98+
// CHECK-DAG: key.description: "self"
99+
// CHECK: ]
100+
// CHECK: key.reusingastcontext: 1

0 commit comments

Comments
 (0)