[CodeCompletion] Migrate postfix expr completion to solver-based

This commit is contained in:
Alex Hoppen
2023-03-14 16:37:14 -07:00
parent c385fe5e87
commit 00eaed3af9
25 changed files with 503 additions and 161 deletions

View File

@@ -519,7 +519,14 @@ public:
void getPostfixKeywordCompletions(Type ExprType, Expr *ParsedExpr);
void getValueExprCompletions(Type ExprType, ValueDecl *VD = nullptr);
/// Add code completion results after an expression of type \p ExprType.
/// This includes members as well as call patterns if \p ExprType is a
/// function type.
/// If \p IsDeclUnapplied is \c true, we are completing after a refernce to
/// \p VD that hasn't been called yet. Thus, \p VD has type \p ExprType and we
/// can use \p VD to enrich call pattern completions of \p ExprType.
void getValueExprCompletions(Type ExprType, ValueDecl *VD = nullptr,
bool IsDeclUnapplied = false);
void collectOperators(SmallVectorImpl<OperatorDecl *> &results);
@@ -529,7 +536,7 @@ public:
void tryPostfixOperator(Expr *expr, PostfixOperatorDecl *op);
void addAssignmentOperator(Type RHSType, Type resultType);
void addAssignmentOperator(Type RHSType);
void addInfixOperatorCompletion(OperatorDecl *op, Type resultType,
Type RHSType);

View File

@@ -20,9 +20,8 @@
namespace swift {
namespace ide {
/// Used to collect and store information needed to perform member completion
/// (\c CompletionKind::DotExpr ) from the solutions formed during expression
/// type-checking.
/// Used to collect and store information needed to perform postfix completion
/// (either <base>.#^COMPLETE^# or <base> #^COMPLETE^#).
class PostfixCompletionCallback : public TypeCheckCompletionCallback {
struct Result {
/// The type that we are completing on. Will never be null.
@@ -32,6 +31,11 @@ class PostfixCompletionCallback : public TypeCheckCompletionCallback {
/// on an expression.
ValueDecl *BaseDecl;
/// Whether \c BaseDecl refers to a function that has not been called yet.
/// In such cases, we know that \p BaseTy is the type of \p BaseDecl and we
/// can use \p BaseDecl for more detailed call pattern completions.
bool IsBaseDeclUnapplied;
/// If the expression we are completing on statically refers to a metatype,
/// that is if it's something like 'MyType'. In such cases we want to offer
/// constructor call pattern completions and don't want to suggeste
@@ -90,8 +94,18 @@ public:
/// \c sawSolution for each solution formed.
void fallbackTypeCheck(DeclContext *DC) override;
void deliverResults(Expr *BaseExpr, DeclContext *DC, SourceLoc DotLoc,
bool IsInSelector, CodeCompletionContext &CompletionCtx,
/// Deliver code completion results that were discoverd by \c sawSolution to
/// \p Consumer.
/// \param DotLoc If we are completing after a dot, the location of the dot,
/// otherwise an invalid SourceLoc.
/// \param IsInSelector Whether we are completing in an Objective-C selector.
/// \param IncludeOperators If operators should be suggested. Assumes that
/// \p DotLoc is invalid
/// \param HasLeadingSpace Whether there is a space separating the exiting
/// expression and the code completion token.
void deliverResults(SourceLoc DotLoc, bool IsInSelector,
bool IncludeOperators, bool HasLeadingSpace,
CodeCompletionContext &CompletionCtx,
CodeCompletionConsumer &Consumer);
};

View File

@@ -147,8 +147,9 @@ public:
/// Complete the \c in keyword in a for-each loop.
virtual void completeForEachInKeyword(){};
/// Complete a given expr-postfix.
virtual void completePostfixExpr(Expr *E, bool hasSpace) {};
/// Complete a expr-postfix. The \c CodeCompletionExpr has the expression it
/// is completing after set as its base.
virtual void completePostfixExpr(CodeCompletionExpr *E, bool hasSpace){};
/// Complete a given expr-postfix, given that there is a following
/// left parenthesis.