Skip to content

Commit 8fe890b

Browse files
committed
[CodeCompletion] Don't suggest precedence groups in expr/type position
Precedence groups should be suggested only at * After colon in operator decls * After 'higherThan:' or 'lowerThan:' in precedence group decls rdar://76977760
1 parent b488e07 commit 8fe890b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IDE/CodeCompletionConsumer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ static MutableArrayRef<CodeCompletionResult *> copyCodeCompletionResults(
7171
};
7272
} else {
7373
shouldIncludeResult = [](const ContextFreeCodeCompletionResult *R) -> bool {
74-
return true;
74+
// PrecedenceGroups are only valid in 'onlyPrecedenceGroups'.
75+
return R->getAssociatedDeclKind() !=
76+
CodeCompletionDeclKind::PrecedenceGroup;
7577
};
7678
}
7779

test/IDE/complete_precedencegroup.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ASSIGNMENT_1 | %FileCheck %s -check-prefix=ASSIGNMENT
2020
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ASSIGNMENT_2 | %FileCheck %s -check-prefix=ASSIGNMENT
2121

22+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GLOBAL_EXPR | %FileCheck %s -check-prefix=PRECEDENCE_GROUP_NEGATIVE
23+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GLOBAL_TYPE | %FileCheck %s -check-prefix=PRECEDENCE_GROUP_NEGATIVE
24+
2225
infix operator +++: #^PRECEDENCE_GROUP_1^#
2326

2427
precedencegroup MyPrecedence1 {
@@ -82,6 +85,13 @@ precedencegroup MyPrecedence12 {
8285

8386
infix operator ---: #^PRECEDENCE_GROUP_CURRFILE^#
8487

88+
func testExpr() {
89+
_ = #^GLOBAL_EXPR^#
90+
}
91+
func testType() {
92+
let _: #^GLOBAL_TYPE^#
93+
}
94+
8595
// ATTRIBUTE_LIST: Begin completions, 4 items
8696
// ATTRIBUTE_LIST: Keyword/None: associativity; name=associativity
8797
// ATTRIBUTE_LIST: Keyword/None: higherThan; name=higherThan
@@ -117,3 +127,7 @@ infix operator ---: #^PRECEDENCE_GROUP_CURRFILE^#
117127
// PRECEDENCE_GROUP_CURRFILE-DAG: Decl[PrecedenceGroup]/CurrModule: MyPrecedence{{[0-9]+}};
118128

119129
// PRECEDENCE_GROUP_MULTIFILE: Decl[PrecedenceGroup]/CurrModule: PrecedenceGroupOtherFile; name=PrecedenceGroupOtherFile
130+
131+
// PRECEDENCE_GROUP_NEGATIVE: Begin completions
132+
// PRECEDENCE_GROUP_NEGATIVE-NOT: Decl[PrecedenceGroup]
133+
// PRECEDENCE_GROUP_NEGATIVE: End completions

0 commit comments

Comments
 (0)