Skip to content

Commit 3218a64

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 de412bb commit 3218a64

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lib/AST/ASTNode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ SourceRange ASTNode::getSourceRange() const {
4141
if (const auto *I = this->dyn_cast<CaseLabelItem *>()) {
4242
return I->getSourceRange();
4343
}
44+
assert(!isNull() && "Null ASTNode doesn't have a source range");
4445
llvm_unreachable("unsupported AST node");
4546
}
4647

lib/Sema/CSRanking.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,15 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
887887
// FIXME: Along with the FIXME below, this is a hack to work around
888888
// problems with restating requirements in protocols.
889889
identical = false;
890+
891+
if (auto anchor = overload.locator->getAnchor()) {
892+
if (cs.containsIDEInspectionTarget(anchor)) {
893+
// Don't rank based on overload choices of function calls that contain the
894+
// code completion token.
895+
continue;
896+
}
897+
}
898+
890899
bool decl1InSubprotocol = false;
891900
bool decl2InSubprotocol = false;
892901
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)