Skip to content

Commit 41a2e94

Browse files
committed
[IDE] Don't rank based on overload choices of function calls that contain the code completion token
Don't rank based on overload choices of function calls that contain the code completion token
1 parent 067f023 commit 41a2e94

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,13 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
883883
// FIXME: Along with the FIXME below, this is a hack to work around
884884
// problems with restating requirements in protocols.
885885
identical = false;
886+
887+
if (cs.containsIDEInspectionTarget(overload.locator->getAnchor())) {
888+
// Don't rank based on overload choices of function calls that contain the
889+
// code completion token.
890+
continue;
891+
}
892+
886893
bool decl1InSubprotocol = false;
887894
bool decl2InSubprotocol = false;
888895
if (dc1->getContextKind() == DeclContextKind::GenericTypeDecl &&
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
func buildView<T>(@MyViewBuilder _ x: () -> T) {}
5+
6+
@resultBuilder struct MyViewBuilder {
7+
static func buildBlock(_ content: MyText) -> MyText { content }
8+
}
9+
10+
struct MyText : Equatable {
11+
init(verbatim content: String) {}
12+
init<S>(_ content: S) where S : StringProtocol {}
13+
}
14+
15+
func test(text: String) {
16+
buildView {
17+
MyText(#^COMPLETE^#text)
18+
}
19+
}
20+
21+
// COMPLETE: Begin completions
22+
// COMPLETE-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]/TypeRelation[Convertible]: ['(']{#verbatim: String#}[')'][#MyText#];
23+
// COMPLETE-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]/TypeRelation[Convertible]: ['(']{#(content): StringProtocol#}[')'][#MyText#];
24+
// COMPLETE-DAG: Decl[LocalVar]/Local/TypeRelation[Convertible]: text[#String#];
25+
// COMPLETE: End completions

0 commit comments

Comments
 (0)