Skip to content

Commit ba2710e

Browse files
committed
[CodeCompletion] Fix the mysteriously missing operators
In the experimental operator completion, we were mysteriously missing some operators like ||. It turns out it was all operators alphabetically after '.', because the filtering code was very broken. rdar://problem/23539465
1 parent 6c0186b commit ba2710e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

test/SourceKit/CodeComplete/complete_operators.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %complete-test -tok=INT_OPERATORS %s | FileCheck %s
22
// RUN: %complete-test -add-inner-results -tok=INT_OPERATORS_INNER %s | FileCheck %s -check-prefix=INNER
33
// RUN: %complete-test -raw -hide-none -tok=INT_OPERATORS %s | FileCheck %s -check-prefix=RAW
4+
// RUN: %complete-test -tok=BOOL_OPERATORS %s | FileCheck %s -check-prefix=BOOL
45

56
struct MyInt {
67
var bigPowers: Int { return 1 }
@@ -47,3 +48,16 @@ func test2(var x: MyInt) {
4748
// RAW: key.description: "++",
4849
// RAW: key.typename: "MyInt",
4950
// RAW: },
51+
52+
struct MyBool {
53+
var foo: Int
54+
}
55+
func &&(x: MyBool, y: MyBool) -> MyBool { return x }
56+
func ||(x: MyBool, y: MyBool) -> MyBool { return x }
57+
58+
func test3(x: MyBool) {
59+
x#^BOOL_OPERATORS^#
60+
}
61+
// BOOL: .
62+
// BOOL: &&
63+
// BOOL: ||

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,18 +858,22 @@ static bool checkInnerResult(CodeCompletionResult *result, bool &hasDot,
858858
if (!chunks.empty() &&
859859
chunks[0].is(CodeCompletionString::Chunk::ChunkKind::Dot)) {
860860
hasDot = true;
861+
return true;
861862
} else if (chunks.size() >= 2 &&
862863
chunks[0].is(
863864
CodeCompletionString::Chunk::ChunkKind::QuestionMark) &&
864865
chunks[1].is(CodeCompletionString::Chunk::ChunkKind::Dot)) {
865866
hasQDot = true;
867+
return true;
866868
} else if (result->getKind() ==
867869
CodeCompletion::SwiftResult::ResultKind::Declaration &&
868870
result->getAssociatedDeclKind() ==
869871
CodeCompletionDeclKind::Constructor) {
870872
hasInit = true;
873+
return true;
874+
} else {
875+
return false;
871876
}
872-
return hasInit || hasDot || hasQDot;
873877
}
874878

875879
template <typename Result>

0 commit comments

Comments
 (0)