Skip to content

Commit 48dd99b

Browse files
committed
[IDE] Don't rank based on overload choices of function calls that contain the code completion token
1 parent 4c186c0 commit 48dd99b

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,25 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
956956
// FIXME: Along with the FIXME below, this is a hack to work around
957957
// problems with restating requirements in protocols.
958958
identical = false;
959+
960+
if (cs.Context.CompletionCallback) {
961+
// Don't rank based on overload choices of function calls that contain the
962+
// code completion token.
963+
ASTNode anchor = simplifyLocatorToAnchor(overload.locator);
964+
if (auto expr = getAsExpr(anchor)) {
965+
// If the anchor is a called function, also don't rank overload choices
966+
// if any of the arguments contain the code completion token.
967+
if (auto apply = dyn_cast_or_null<ApplyExpr>(cs.getParentExpr(expr))) {
968+
if (apply->getFn() == expr) {
969+
anchor = apply;
970+
}
971+
}
972+
}
973+
if (anchor && cs.containsIDEInspectionTarget(anchor)) {
974+
continue;
975+
}
976+
}
977+
959978
bool decl1InSubprotocol = false;
960979
bool decl2InSubprotocol = false;
961980
if (dc1->getContextKind() == DeclContextKind::GenericTypeDecl &&

test/IDE/complete_ambiguous.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ struct Struct123: Equatable {
443443
}
444444
func testBestSolutionFilter() {
445445
let a = Struct123();
446-
let b = [Struct123]().first(where: { $0 == a && 1 + 90 * 5 / 8 == 45 * -10 })?.structMem != .#^BEST_SOLUTION_FILTER?xfail=rdar73282163^#
447-
let c = min(10.3, 10 / 10.4) < 6 / 7 ? true : Optional(a)?.structMem != .#^BEST_SOLUTION_FILTER2?check=BEST_SOLUTION_FILTER;xfail=rdar73282163^#
446+
let b = [Struct123]().first(where: { $0 == a && 1 + 90 * 5 / 8 == 45 * -10 })?.structMem != .#^BEST_SOLUTION_FILTER^#
447+
let c = min(10.3, 10 / 10.4) < 6 / 7 ? true : Optional(a)?.structMem != .#^BEST_SOLUTION_FILTER2?check=BEST_SOLUTION_FILTER^#
448448
}
449449

450450
// BEST_SOLUTION_FILTER-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: enumElem[#Enum123#]{{; name=.+$}}

test/IDE/complete_in_closures.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,16 @@ func testReferenceToVariableDefinedInClosure() {
485485
// VARIABLE_DEFINED_IN_CLOSURE: Decl[LocalVar]/Local: item[#String#]; name=item
486486
}
487487

488+
func testBinaryOperatorWithEnum() {
489+
func closureWithEnum(completionHandler: (SomeEnum) -> Void) {}
490+
491+
closureWithEnum { foo in
492+
if foo != .#^BINARY_OPERATOR_WITH_ENUM^# {
493+
}
494+
}
495+
// BINARY_OPERATOR_WITH_ENUM: Begin completions
496+
// BINARY_OPERATOR_WITH_ENUM-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: north[#SomeEnum#]
497+
// BINARY_OPERATOR_WITH_ENUM-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: south[#SomeEnum#]
498+
// BINARY_OPERATOR_WITH_ENUM: End completions
499+
500+
}

0 commit comments

Comments
 (0)