[CodeCompletion] Dont mark type mismatching items 'not recommended'

func foo() {}
let a: Int = #^HERE^#

Previously, we marked 'foo()' as 'NotRecommented' because 'Void' doesn't
have any member hence it cannot be 'Int'. But it wass confusing with
'deprecated'.

Now that we output 'typerelation' which is 'invalid' in this case. So clients
can deprioritize results, or even filter them out.

rdar://problem/57726512
This commit is contained in:
Rintaro Ishizaki
2020-05-01 12:52:40 -07:00
parent 9f18130760
commit e9c438cdd5
20 changed files with 164 additions and 137 deletions

View File

@@ -114,7 +114,7 @@ std::vector<Completion *> SourceKit::CodeCompletion::extendCompletions(
using ChunkKind = ide::CodeCompletionString::Chunk::ChunkKind;
if (chunk.is(ChunkKind::TypeAnnotation) && chunk.hasText() &&
chunk.getText() == "Void") {
builder.setNotRecommended(Completion::TypeMismatch);
builder.setExpectedTypeRelation(Completion::Invalid);
}
}
}
@@ -550,7 +550,9 @@ void CodeCompletionOrganizer::Impl::addCompletionsWithFilter(
if (rules.hideCompletion(completion))
continue;
if (options.hideLowPriority && completion->isNotRecommended())
if (options.hideLowPriority &&
(completion->isNotRecommended() ||
completion->getExpectedTypeRelation() == Completion::Invalid))
continue;
NameStyle style(completion->getName());
@@ -745,12 +747,9 @@ static ResultBucket getResultBucket(Item &item, bool hasRequiredTypes,
if (completion->isOperator())
return ResultBucket::Operator;
bool matchesType =
completion->getExpectedTypeRelation() >= Completion::Convertible;
switch (completion->getKind()) {
case Completion::Literal:
if (matchesType) {
if (completion->getExpectedTypeRelation() >= Completion::Convertible) {
return ResultBucket::LiteralTypeMatch;
} else if (!hasRequiredTypes) {
return ResultBucket::Literal;
@@ -765,7 +764,19 @@ static ResultBucket getResultBucket(Item &item, bool hasRequiredTypes,
: ResultBucket::Normal;
case Completion::Pattern:
case Completion::Declaration:
return matchesType ? ResultBucket::NormalTypeMatch : ResultBucket::Normal;
switch (completion->getExpectedTypeRelation()) {
case swift::ide::CodeCompletionResult::Convertible:
case swift::ide::CodeCompletionResult::Identical:
return ResultBucket::NormalTypeMatch;
case swift::ide::CodeCompletionResult::NotApplicable:
case swift::ide::CodeCompletionResult::Unknown:
case swift::ide::CodeCompletionResult::Unrelated:
return ResultBucket::Normal;
case swift::ide::CodeCompletionResult::Invalid:
if (!skipMetaGroups)
return ResultBucket::NotRecommended;
return ResultBucket::Normal;
}
case Completion::BuiltinOperator:
llvm_unreachable("operators should be handled above");
}
@@ -1256,8 +1267,7 @@ void CompletionBuilder::getFilterName(CodeCompletionString *str,
CompletionBuilder::CompletionBuilder(CompletionSink &sink, SwiftResult &base)
: sink(sink), current(base) {
isNotRecommended = current.isNotRecommended();
notRecommendedReason = current.getNotRecommendedReason();
typeRelation = current.getExpectedTypeRelation();
semanticContext = current.getSemanticContext();
completionString =
const_cast<CodeCompletionString *>(current.getCompletionString());
@@ -1305,12 +1315,13 @@ Completion *CompletionBuilder::finish() {
base = SwiftResult(
semanticContext, current.getNumBytesToErase(), completionString,
current.getAssociatedDeclKind(), current.getModuleName(),
isNotRecommended, notRecommendedReason, current.getBriefDocComment(),
current.getAssociatedUSRs(), current.getDeclKeywords(), opKind);
current.isNotRecommended(), current.getNotRecommendedReason(),
current.getBriefDocComment(), current.getAssociatedUSRs(),
current.getDeclKeywords(), typeRelation, opKind);
} else {
base = SwiftResult(current.getKind(), semanticContext,
current.getNumBytesToErase(), completionString,
current.getExpectedTypeRelation(), opKind);
typeRelation, opKind);
}
llvm::raw_svector_ostream OSS(nameStorage);