[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

@@ -228,15 +228,16 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
CodeCompletionResult *result = nullptr;
if (kind == CodeCompletionResult::Declaration) {
result = new (*V.Sink.Allocator) CodeCompletionResult(
context, numBytesToErase, string, declKind, isSystem, moduleName,
notRecommended, briefDocComment,
context, /*IsArgumentLabels=*/false, numBytesToErase, string,
declKind, isSystem, moduleName, notRecommended, briefDocComment,
copyArray(*V.Sink.Allocator, ArrayRef<StringRef>(assocUSRs)),
copyArray(*V.Sink.Allocator,
ArrayRef<std::pair<StringRef, StringRef>>(declKeywords)),
CodeCompletionResult::Unknown, opKind);
} else {
result = new (*V.Sink.Allocator)
CodeCompletionResult(kind, context, numBytesToErase, string,
CodeCompletionResult(kind, context, /*IsArgumentLabels=*/false,
numBytesToErase, string,
CodeCompletionResult::NotApplicable, opKind);
}
@@ -340,6 +341,7 @@ static void writeCachedModule(llvm::raw_ostream &out,
{
endian::Writer LE(results, little);
for (CodeCompletionResult *R : V.Sink.Results) {
assert(!R->isArgumentLabels() && "Argument labels should not be cached");
// FIXME: compress bitfield
LE.write(static_cast<uint8_t>(R->getKind()));
if (R->getKind() == CodeCompletionResult::Declaration)