mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user