[CodeCompletion] Annotated result type

Introduced 'TypeAnnotationBegin' chunk kind for grouping the result type
name chunks.

rdar://problem/62617558
This commit is contained in:
Rintaro Ishizaki
2020-05-05 19:57:03 -07:00
parent bfde3b03a8
commit 7086ffb79f
14 changed files with 506 additions and 216 deletions

View File

@@ -110,13 +110,26 @@ std::vector<Completion *> SourceKit::CodeCompletion::extendCompletions(
// FIXME: because other-module results are cached, they will not be
// given a type-relation of invalid. As a hack, we look at the text of
// the result type and look for 'Void'.
for (auto &chunk : result->getCompletionString()->getChunks()) {
bool isVoid = false;
auto chunks = result->getCompletionString()->getChunks();
for (auto i = chunks.begin(), e = chunks.end(); i != e; ++i) {
using ChunkKind = ide::CodeCompletionString::Chunk::ChunkKind;
if (chunk.is(ChunkKind::TypeAnnotation) && chunk.hasText() &&
chunk.getText() == "Void") {
builder.setExpectedTypeRelation(Completion::Invalid);
bool isVoid = false;
if (i->is(ChunkKind::TypeAnnotation)) {
isVoid = i->getText() == "Void";
break;
} else if (i->is(ChunkKind::TypeAnnotationBegin)) {
auto n = i + 1, t = i + 2;
isVoid =
// i+1 has text 'Void'.
n != e && n->hasText() && n->getText() == "Void" &&
// i+2 terminates the group.
(t == e || t->endsPreviousNestedGroup(i->getNestingLevel()));
break;
}
}
if (isVoid)
builder.setExpectedTypeRelation(Completion::Invalid);
}
}
@@ -1240,14 +1253,11 @@ void CompletionBuilder::getFilterName(CodeCompletionString *str,
case ChunkKind::Ampersand:
case ChunkKind::OptionalMethodCallTail:
continue;
case ChunkKind::CallParameterTypeBegin: {
// Skip call parameter type type structure.
case ChunkKind::CallParameterTypeBegin:
case ChunkKind::TypeAnnotationBegin: {
// Skip call parameter type or type annotation structure.
auto nestingLevel = C.getNestingLevel();
++i;
for (; i != e; ++i) {
if (i->endsPreviousNestedGroup(nestingLevel))
break;
}
do { ++i; } while (i != e && !i->endsPreviousNestedGroup(nestingLevel));
--i;
continue;
}