File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -3055,6 +3055,10 @@ class alignas(1 << AttrAlignInBits) TypeAttribute
30553055 // / Return the name (like "autoclosure") for an attribute ID.
30563056 static const char *getAttrName (TypeAttrKind kind);
30573057
3058+ // / Returns whether the given attribute is considered "user inaccessible",
3059+ // / which affects e.g whether it shows up in code completion.
3060+ static bool isUserInaccessible (TypeAttrKind DK);
3061+
30583062 static TypeAttribute *createSimple (const ASTContext &context,
30593063 TypeAttrKind kind,
30603064 SourceLoc atLoc,
Original file line number Diff line number Diff line change @@ -145,6 +145,24 @@ const char *TypeAttribute::getAttrName(TypeAttrKind kind) {
145145 llvm_unreachable (" unknown type attribute kind" );
146146}
147147
148+ bool TypeAttribute::isUserInaccessible (TypeAttrKind DK) {
149+ // Currently we can base this off whether it is underscored or for SIL.
150+ // TODO: We could introduce a similar options scheme to DECL_ATTR if we ever
151+ // need a user-inaccessible non-underscored attribute.
152+ switch (DK) {
153+ // SIL attributes are always considered user-inaccessible.
154+ #define SIL_TYPE_ATTR (SPELLING, C ) \
155+ case TypeAttrKind::C: \
156+ return true ;
157+ // For non-SIL attributes, check whether the spelling is underscored.
158+ #define TYPE_ATTR (SPELLING, C ) \
159+ case TypeAttrKind::C: \
160+ return StringRef (#SPELLING).starts_with (" _" );
161+ #include " swift/AST/TypeAttr.def"
162+ }
163+ llvm_unreachable (" unhandled case in switch!" );
164+ }
165+
148166TypeAttribute *TypeAttribute::createSimple (const ASTContext &context,
149167 TypeAttrKind kind,
150168 SourceLoc atLoc,
Original file line number Diff line number Diff line change @@ -3137,12 +3137,21 @@ void CompletionLookup::getTypeAttributeKeywordCompletions() {
31373137 CodeCompletionResultKind::Keyword, SemanticContextKind::None);
31383138 Builder.addAttributeKeyword (Name, " Type Attribute" );
31393139 };
3140- addTypeAttr (" autoclosure" );
3140+
3141+ // Add simple user-accessible attributes.
3142+ #define SIL_TYPE_ATTR (SPELLING, C )
3143+ #define SIMPLE_SIL_TYPE_ATTR (SPELLING, C )
3144+ #define SIMPLE_TYPE_ATTR (SPELLING, C ) \
3145+ if (!TypeAttribute::isUserInaccessible (TypeAttrKind::C)) \
3146+ addTypeAttr (#SPELLING);
3147+ #include " swift/AST/TypeAttr.def"
3148+
3149+ // Add non-simple cases.
31413150 addTypeAttr (" convention(swift)" );
31423151 addTypeAttr (" convention(block)" );
31433152 addTypeAttr (" convention(c)" );
31443153 addTypeAttr (" convention(thin)" );
3145- addTypeAttr (" escaping " );
3154+ addTypeAttr (" isolated(any) " );
31463155}
31473156
31483157void CompletionLookup::collectPrecedenceGroups () {
You can’t perform that action at this time.
0 commit comments