mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #58999 from ahoppen/pr/cache-function-asyncness
[CodeCompletion] Cache 'async'-ness of free functions
This commit is contained in:
@@ -329,6 +329,7 @@ class ContextFreeCodeCompletionResult {
|
||||
static_assert(int(CodeCompletionOperatorKind::MAX_VALUE) < 1 << 6, "");
|
||||
|
||||
bool IsSystem : 1;
|
||||
bool IsAsync : 1;
|
||||
CodeCompletionString *CompletionString;
|
||||
NullTerminatedStringRef ModuleName;
|
||||
NullTerminatedStringRef BriefDocComment;
|
||||
@@ -344,6 +345,10 @@ class ContextFreeCodeCompletionResult {
|
||||
NullTerminatedStringRef DiagnosticMessage;
|
||||
NullTerminatedStringRef FilterName;
|
||||
|
||||
/// If the result represents a \c ValueDecl the name by which this decl should
|
||||
/// be refered to in diagnostics.
|
||||
NullTerminatedStringRef NameForDiagnostics;
|
||||
|
||||
public:
|
||||
/// Memberwise initializer. \p AssociatedKInd is opaque and will be
|
||||
/// interpreted based on \p Kind. If \p KnownOperatorKind is \c None and the
|
||||
@@ -355,7 +360,7 @@ public:
|
||||
/// \c CodeCompletionResultSink as the result itself.
|
||||
ContextFreeCodeCompletionResult(
|
||||
CodeCompletionResultKind Kind, uint8_t AssociatedKind,
|
||||
CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem,
|
||||
CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem, bool IsAsync,
|
||||
CodeCompletionString *CompletionString,
|
||||
NullTerminatedStringRef ModuleName,
|
||||
NullTerminatedStringRef BriefDocComment,
|
||||
@@ -364,13 +369,15 @@ public:
|
||||
ContextFreeNotRecommendedReason NotRecommended,
|
||||
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
|
||||
NullTerminatedStringRef DiagnosticMessage,
|
||||
NullTerminatedStringRef FilterName)
|
||||
NullTerminatedStringRef FilterName,
|
||||
NullTerminatedStringRef NameForDiagnostics)
|
||||
: Kind(Kind), KnownOperatorKind(KnownOperatorKind), IsSystem(IsSystem),
|
||||
CompletionString(CompletionString), ModuleName(ModuleName),
|
||||
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
|
||||
ResultType(ResultType), NotRecommended(NotRecommended),
|
||||
DiagnosticSeverity(DiagnosticSeverity),
|
||||
DiagnosticMessage(DiagnosticMessage), FilterName(FilterName) {
|
||||
IsAsync(IsAsync), CompletionString(CompletionString),
|
||||
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
|
||||
AssociatedUSRs(AssociatedUSRs), ResultType(ResultType),
|
||||
NotRecommended(NotRecommended), DiagnosticSeverity(DiagnosticSeverity),
|
||||
DiagnosticMessage(DiagnosticMessage), FilterName(FilterName),
|
||||
NameForDiagnostics(NameForDiagnostics) {
|
||||
this->AssociatedKind.Opaque = AssociatedKind;
|
||||
assert((NotRecommended == ContextFreeNotRecommendedReason::None) ==
|
||||
(DiagnosticSeverity == CodeCompletionDiagnosticSeverity::None) &&
|
||||
@@ -396,7 +403,7 @@ public:
|
||||
static ContextFreeCodeCompletionResult *createPatternOrBuiltInOperatorResult(
|
||||
CodeCompletionResultSink &Sink, CodeCompletionResultKind Kind,
|
||||
CodeCompletionString *CompletionString,
|
||||
CodeCompletionOperatorKind KnownOperatorKind,
|
||||
CodeCompletionOperatorKind KnownOperatorKind, bool IsAsync,
|
||||
NullTerminatedStringRef BriefDocComment,
|
||||
CodeCompletionResultType ResultType,
|
||||
ContextFreeNotRecommendedReason NotRecommended,
|
||||
@@ -431,15 +438,17 @@ public:
|
||||
/// \note The caller must ensure that the \p CompletionString and all
|
||||
/// \c StringRefs outlive this result, typically by storing them in the same
|
||||
/// \c CodeCompletionResultSink as the result itself.
|
||||
static ContextFreeCodeCompletionResult *createDeclResult(
|
||||
CodeCompletionResultSink &Sink, CodeCompletionString *CompletionString,
|
||||
const Decl *AssociatedDecl, NullTerminatedStringRef ModuleName,
|
||||
NullTerminatedStringRef BriefDocComment,
|
||||
ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
|
||||
CodeCompletionResultType ResultType,
|
||||
ContextFreeNotRecommendedReason NotRecommended,
|
||||
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
|
||||
NullTerminatedStringRef DiagnosticMessage);
|
||||
static ContextFreeCodeCompletionResult *
|
||||
createDeclResult(CodeCompletionResultSink &Sink,
|
||||
CodeCompletionString *CompletionString,
|
||||
const Decl *AssociatedDecl, bool IsAsync,
|
||||
NullTerminatedStringRef ModuleName,
|
||||
NullTerminatedStringRef BriefDocComment,
|
||||
ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
|
||||
CodeCompletionResultType ResultType,
|
||||
ContextFreeNotRecommendedReason NotRecommended,
|
||||
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
|
||||
NullTerminatedStringRef DiagnosticMessage);
|
||||
|
||||
CodeCompletionResultKind getKind() const { return Kind; }
|
||||
|
||||
@@ -469,6 +478,8 @@ public:
|
||||
|
||||
bool isSystem() const { return IsSystem; };
|
||||
|
||||
bool isAsync() const { return IsAsync; };
|
||||
|
||||
CodeCompletionString *getCompletionString() const { return CompletionString; }
|
||||
|
||||
NullTerminatedStringRef getModuleName() const { return ModuleName; }
|
||||
@@ -494,6 +505,10 @@ public:
|
||||
|
||||
NullTerminatedStringRef getFilterName() const { return FilterName; }
|
||||
|
||||
NullTerminatedStringRef getNameForDiagnostics() const {
|
||||
return NameForDiagnostics;
|
||||
}
|
||||
|
||||
bool isOperator() const {
|
||||
if (getKind() == CodeCompletionResultKind::Declaration) {
|
||||
switch (getAssociatedDeclKind()) {
|
||||
@@ -531,11 +546,6 @@ class CodeCompletionResult {
|
||||
ContextualNotRecommendedReason NotRecommended : 4;
|
||||
static_assert(int(ContextualNotRecommendedReason::MAX_VALUE) < 1 << 4, "");
|
||||
|
||||
CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3;
|
||||
static_assert(int(CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3, "");
|
||||
|
||||
NullTerminatedStringRef DiagnosticMessage;
|
||||
|
||||
/// The number of bytes to the left of the code completion point that
|
||||
/// should be erased first if this completion string is inserted in the
|
||||
/// editor buffer.
|
||||
@@ -556,14 +566,10 @@ private:
|
||||
SemanticContextKind SemanticContext,
|
||||
CodeCompletionFlair Flair, uint8_t NumBytesToErase,
|
||||
CodeCompletionResultTypeRelation TypeDistance,
|
||||
ContextualNotRecommendedReason NotRecommended,
|
||||
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
|
||||
NullTerminatedStringRef DiagnosticMessage)
|
||||
ContextualNotRecommendedReason NotRecommended)
|
||||
: ContextFree(ContextFree), SemanticContext(SemanticContext),
|
||||
Flair(Flair.toRaw()), NotRecommended(NotRecommended),
|
||||
DiagnosticSeverity(DiagnosticSeverity),
|
||||
DiagnosticMessage(DiagnosticMessage), NumBytesToErase(NumBytesToErase),
|
||||
TypeDistance(TypeDistance) {}
|
||||
NumBytesToErase(NumBytesToErase), TypeDistance(TypeDistance) {}
|
||||
|
||||
public:
|
||||
/// Enrich a \c ContextFreeCodeCompletionResult with the following contextual
|
||||
@@ -581,9 +587,8 @@ public:
|
||||
const ExpectedTypeContext *TypeContext,
|
||||
const DeclContext *DC,
|
||||
const USRBasedTypeContext *USRTypeContext,
|
||||
ContextualNotRecommendedReason NotRecommended,
|
||||
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
|
||||
NullTerminatedStringRef DiagnosticMessage);
|
||||
bool CanCurrDeclContextHandleAsync,
|
||||
ContextualNotRecommendedReason NotRecommended);
|
||||
|
||||
const ContextFreeCodeCompletionResult &getContextFreeResult() const {
|
||||
return ContextFree;
|
||||
@@ -702,37 +707,23 @@ public:
|
||||
return getContextFreeResult().getAssociatedUSRs();
|
||||
}
|
||||
|
||||
/// Get the contextual diagnostic severity. This disregards context-free
|
||||
/// diagnostics.
|
||||
CodeCompletionDiagnosticSeverity getContextualDiagnosticSeverity() const {
|
||||
return DiagnosticSeverity;
|
||||
}
|
||||
/// Get the contextual diagnostic severity and message. This disregards
|
||||
/// context-free diagnostics.
|
||||
std::pair<CodeCompletionDiagnosticSeverity, NullTerminatedStringRef>
|
||||
getContextualDiagnosticSeverityAndMessage(SmallVectorImpl<char> &Scratch,
|
||||
const ASTContext &Ctx) const;
|
||||
|
||||
/// Get the contextual diagnostic message. This disregards context-free
|
||||
/// diagnostics.
|
||||
NullTerminatedStringRef getContextualDiagnosticMessage() const {
|
||||
return DiagnosticMessage;
|
||||
}
|
||||
|
||||
/// Return the contextual diagnostic severity if there was a contextual
|
||||
/// diagnostic. If there is no contextual diagnostic, return the context-free
|
||||
/// diagnostic severity.
|
||||
CodeCompletionDiagnosticSeverity getDiagnosticSeverity() const {
|
||||
/// Return the contextual diagnostic severity and message if there was a
|
||||
/// contextual diagnostic. If there is no contextual diagnostic, return the
|
||||
/// context-free diagnostic severity and message.
|
||||
std::pair<CodeCompletionDiagnosticSeverity, NullTerminatedStringRef>
|
||||
getDiagnosticSeverityAndMessage(SmallVectorImpl<char> &Scratch,
|
||||
const ASTContext &Ctx) const {
|
||||
if (NotRecommended != ContextualNotRecommendedReason::None) {
|
||||
return DiagnosticSeverity;
|
||||
return getContextualDiagnosticSeverityAndMessage(Scratch, Ctx);
|
||||
} else {
|
||||
return getContextFreeResult().getDiagnosticSeverity();
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the contextual diagnostic message if there was a contextual
|
||||
/// diagnostic. If there is no contextual diagnostic, return the context-free
|
||||
/// diagnostic message.
|
||||
NullTerminatedStringRef getDiagnosticMessage() const {
|
||||
if (NotRecommended != ContextualNotRecommendedReason::None) {
|
||||
return DiagnosticMessage;
|
||||
} else {
|
||||
return getContextFreeResult().getDiagnosticMessage();
|
||||
return std::make_pair(getContextFreeResult().getDiagnosticSeverity(),
|
||||
getContextFreeResult().getDiagnosticMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user