Skip to content

[5.7][CodeCompletion] Don't suggest precedence groups in expr/type position #59267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/IDE/CodeCompletionConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static MutableArrayRef<CodeCompletionResult *> copyCodeCompletionResults(
};
} else {
shouldIncludeResult = [](const ContextFreeCodeCompletionResult *R) -> bool {
return true;
// PrecedenceGroups are only valid in 'onlyPrecedenceGroups'.
return R->getAssociatedDeclKind() !=
CodeCompletionDeclKind::PrecedenceGroup;
};
}

Expand Down
14 changes: 14 additions & 0 deletions test/IDE/complete_precedencegroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ASSIGNMENT_1 | %FileCheck %s -check-prefix=ASSIGNMENT
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ASSIGNMENT_2 | %FileCheck %s -check-prefix=ASSIGNMENT

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GLOBAL_EXPR | %FileCheck %s -check-prefix=PRECEDENCE_GROUP_NEGATIVE
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GLOBAL_TYPE | %FileCheck %s -check-prefix=PRECEDENCE_GROUP_NEGATIVE

infix operator +++: #^PRECEDENCE_GROUP_1^#

precedencegroup MyPrecedence1 {
Expand Down Expand Up @@ -82,6 +85,13 @@ precedencegroup MyPrecedence12 {

infix operator ---: #^PRECEDENCE_GROUP_CURRFILE^#

func testExpr() {
_ = #^GLOBAL_EXPR^#
}
func testType() {
let _: #^GLOBAL_TYPE^#
}

// ATTRIBUTE_LIST: Begin completions, 4 items
// ATTRIBUTE_LIST: Keyword/None: associativity; name=associativity
// ATTRIBUTE_LIST: Keyword/None: higherThan; name=higherThan
Expand Down Expand Up @@ -117,3 +127,7 @@ infix operator ---: #^PRECEDENCE_GROUP_CURRFILE^#
// PRECEDENCE_GROUP_CURRFILE-DAG: Decl[PrecedenceGroup]/CurrModule: MyPrecedence{{[0-9]+}};

// PRECEDENCE_GROUP_MULTIFILE: Decl[PrecedenceGroup]/CurrModule: PrecedenceGroupOtherFile; name=PrecedenceGroupOtherFile

// PRECEDENCE_GROUP_NEGATIVE: Begin completions
// PRECEDENCE_GROUP_NEGATIVE-NOT: Decl[PrecedenceGroup]
// PRECEDENCE_GROUP_NEGATIVE: End completions