[CodeCompletion] Prioritize call argument pattern

struct Foo {
    init(_ arg1: String, arg2: Int) {}
    init(label: Int) {}
  }
  func test(strVal: String) {
    _ = Foo(<HERE>)
  }

In this case, 'strVal' was prioritized because it can use as an argument
for 'init(_:arg2:)'. However, argument labels are almost always
preferable, and if the user actually want 'strVal', they can input a few
characters to get it at the top. So we should always prioritize call
argument patterns.

rdar://77188260
This commit is contained in:
Rintaro Ishizaki
2021-04-29 13:23:15 -07:00
parent fe9a290823
commit 3c2433c942
7 changed files with 65 additions and 19 deletions

View File

@@ -1294,8 +1294,8 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
}
return new (*Sink.Allocator) CodeCompletionResult(
SemanticContext, NumBytesToErase, CCS, AssociatedDecl, ModuleName,
NotRecReason, copyString(*Sink.Allocator, BriefComment),
SemanticContext, IsArgumentLabels, NumBytesToErase, CCS, AssociatedDecl,
ModuleName, NotRecReason, copyString(*Sink.Allocator, BriefComment),
copyAssociatedUSRs(*Sink.Allocator, AssociatedDecl),
copyArray(*Sink.Allocator, CommentWords), ExpectedTypeRelation);
}
@@ -1303,22 +1303,22 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
case CodeCompletionResult::ResultKind::Keyword:
return new (*Sink.Allocator)
CodeCompletionResult(
KeywordKind, SemanticContext, NumBytesToErase,
KeywordKind, SemanticContext, IsArgumentLabels, NumBytesToErase,
CCS, ExpectedTypeRelation,
copyString(*Sink.Allocator, BriefDocComment));
case CodeCompletionResult::ResultKind::BuiltinOperator:
case CodeCompletionResult::ResultKind::Pattern:
return new (*Sink.Allocator) CodeCompletionResult(
Kind, SemanticContext, NumBytesToErase, CCS, ExpectedTypeRelation,
CodeCompletionOperatorKind::None,
Kind, SemanticContext, IsArgumentLabels, NumBytesToErase, CCS,
ExpectedTypeRelation, CodeCompletionOperatorKind::None,
copyString(*Sink.Allocator, BriefDocComment));
case CodeCompletionResult::ResultKind::Literal:
assert(LiteralKind.hasValue());
return new (*Sink.Allocator)
CodeCompletionResult(*LiteralKind, SemanticContext, NumBytesToErase,
CCS, ExpectedTypeRelation);
CodeCompletionResult(*LiteralKind, SemanticContext, IsArgumentLabels,
NumBytesToErase, CCS, ExpectedTypeRelation);
}
llvm_unreachable("Unhandled CodeCompletionResult in switch.");
@@ -2895,6 +2895,7 @@ public:
: CodeCompletionResult::ResultKind::Pattern,
SemanticContext ? *SemanticContext : getSemanticContextKind(AFD),
expectedTypeContext);
Builder.setIsArgumentLabels();
if (AFD) {
Builder.setAssociatedDecl(AFD);
setClangDeclKeywords(AFD, Pairs, Builder);