mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +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:
@@ -158,7 +158,7 @@ bool SourceKit::CodeCompletion::addCustomCompletions(
|
||||
CodeCompletion::SwiftResult swiftResult(
|
||||
CodeCompletion::SwiftResult::ResultKind::Pattern,
|
||||
SemanticContextKind::ExpressionSpecific,
|
||||
/*NumBytesToErase=*/0, completionString,
|
||||
/*IsArgumentLabels=*/false, /*NumBytesToErase=*/0, completionString,
|
||||
CodeCompletionResult::ExpectedTypeRelation::Unknown);
|
||||
|
||||
CompletionBuilder builder(sink, swiftResult);
|
||||
@@ -666,6 +666,9 @@ static ResultBucket getResultBucket(Item &item, bool hasRequiredTypes,
|
||||
!skipMetaGroups)
|
||||
return ResultBucket::ExpressionSpecific;
|
||||
|
||||
if (completion->isArgumentLabels() && !skipMetaGroups)
|
||||
return ResultBucket::ExpressionSpecific;
|
||||
|
||||
if (completion->isOperator())
|
||||
return ResultBucket::Operator;
|
||||
|
||||
@@ -1167,13 +1170,15 @@ Completion *CompletionBuilder::finish() {
|
||||
|
||||
if (current.getKind() == SwiftResult::Declaration) {
|
||||
base = SwiftResult(
|
||||
semanticContext, current.getNumBytesToErase(), completionString,
|
||||
semanticContext, current.isArgumentLabels(),
|
||||
current.getNumBytesToErase(), completionString,
|
||||
current.getAssociatedDeclKind(), current.isSystem(),
|
||||
current.getModuleName(), current.getNotRecommendedReason(),
|
||||
current.getBriefDocComment(), current.getAssociatedUSRs(),
|
||||
current.getDeclKeywords(), typeRelation, opKind);
|
||||
} else {
|
||||
base = SwiftResult(current.getKind(), semanticContext,
|
||||
current.isArgumentLabels(),
|
||||
current.getNumBytesToErase(), completionString,
|
||||
typeRelation, opKind);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user