Fix lifetime of type context in result builder

There usually won't be a lot of expected types, so just use a
SmallVector and copy it instead of trying to get tricky with the
lifetime.
This commit is contained in:
Ben Langmuir
2019-03-19 07:04:39 -07:00
parent b817cbb9bc
commit f8a3afb7bb
2 changed files with 21 additions and 23 deletions

View File

@@ -867,25 +867,6 @@ ArrayRef<StringRef> copyAssociatedUSRs(llvm::BumpPtrAllocator &Allocator,
return ArrayRef<StringRef>();
}
/// The expected contextual type(s) for code-completion.
struct ide::ExpectedTypeContext {
/// Possible types of the code completion expression.
std::vector<Type> possibleTypes;
/// Whether the `ExpectedTypes` comes from a single-expression body, e.g.
/// `foo({ here })`.
///
/// Since the input may be incomplete, we take into account that the types are
/// only a hint.
bool isSingleExpressionBody = false;
bool empty() const { return possibleTypes.empty(); }
ExpectedTypeContext() = default;
ExpectedTypeContext(std::vector<Type> types, bool isSingleExpressionBody)
: possibleTypes(types), isSingleExpressionBody(isSingleExpressionBody) {}
};
static CodeCompletionResult::ExpectedTypeRelation calculateTypeRelation(
Type Ty,
Type ExpectedTy,
@@ -1289,11 +1270,10 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
if (ST.isNull() || ST->is<ErrorType>())
return;
ExpectedTypeContext empty;
CodeCompletionResultBuilder Builder(Sink,
CodeCompletionResult::ResultKind::Keyword,
SemanticContextKind::CurrentNominal,
empty);
{});
Builder.setKeywordKind(CodeCompletionKeywordKind::kw_super);
Builder.addTextChunk("super");
Builder.addTypeAnnotation(ST.getString());