Skip to content

Commit d5e9750

Browse files
committed
[CodeCompletion] Suggest freestanding after @
rdar://108163121
1 parent db14ae8 commit d5e9750

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

include/swift/IDE/CompletionLookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
581581

582582
static bool canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
583583
bool IsConcurrencyEnabled,
584-
Optional<DeclKind> DK);
584+
Optional<DeclKind> DK, StringRef Name);
585585

586586
void getAttributeDeclCompletions(bool IsInSil, Optional<DeclKind> DK);
587587

lib/IDE/CompletionLookup.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,8 @@ void CompletionLookup::getGenericRequirementCompletions(
29662966

29672967
bool CompletionLookup::canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
29682968
bool IsConcurrencyEnabled,
2969-
Optional<DeclKind> DK) {
2969+
Optional<DeclKind> DK,
2970+
StringRef Name) {
29702971
if (DeclAttribute::isUserInaccessible(DAK))
29712972
return false;
29722973
if (DeclAttribute::isDeclModifier(DAK))
@@ -2979,6 +2980,11 @@ bool CompletionLookup::canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
29792980
return false;
29802981
if (!DK.has_value())
29812982
return true;
2983+
// Hide underscored attributes even if they are not marked as user
2984+
// inaccessible. This can happen for attributes that are an underscored
2985+
// variant of a user-accessible attribute (like @_backDeployed)
2986+
if (Name.empty() || Name[0] == '_')
2987+
return false;
29822988
return DeclAttribute::canAttributeAppearOnDeclKind(DAK, DK.value());
29832989
}
29842990

@@ -2997,9 +3003,10 @@ void CompletionLookup::getAttributeDeclCompletions(bool IsInSil,
29973003
}
29983004
bool IsConcurrencyEnabled = Ctx.LangOpts.EnableExperimentalConcurrency;
29993005
std::string Description = TargetName.str() + " Attribute";
3006+
#define DECL_ATTR_ALIAS(KEYWORD, NAME) DECL_ATTR(KEYWORD, NAME, 0, 0)
30003007
#define DECL_ATTR(KEYWORD, NAME, ...) \
3001-
if (canUseAttributeOnDecl(DAK_##NAME, IsInSil, IsConcurrencyEnabled, \
3002-
DK)) \
3008+
if (canUseAttributeOnDecl(DAK_##NAME, IsInSil, IsConcurrencyEnabled, DK, \
3009+
#KEYWORD)) \
30033010
addDeclAttrKeyword(#KEYWORD, Description);
30043011
#include "swift/AST/Attr.def"
30053012
}

test/IDE/complete_decl_attribute.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ struct _S {
323323
// ON_MEMBER_LAST-DAG: Keyword/None: preconcurrency[#Declaration Attribute#]; name=preconcurrency
324324
// ON_MEMBER_LAST-DAG: Keyword/None: runtimeMetadata[#Declaration Attribute#]; name=runtimeMetadata
325325
// ON_MEMBER_LAST-DAG: Keyword/None: attached[#Declaration Attribute#]; name=attached
326+
// ON_MEMBER_LAST-DAG: Keyword/None: freestanding[#Declaration Attribute#]; name=freestanding
326327
// ON_MEMBER_LAST-NOT: Keyword
327328
// ON_MEMBER_LAST-DAG: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
328329
// ON_MEMBER_LAST-DAG: Decl[Struct]/CurrModule/TypeRelation[Convertible]: MyPropertyWrapper[#MyPropertyWrapper#]; name=MyPropertyWrapper
@@ -358,6 +359,7 @@ func dummy2() {}
358359
@#^KEYWORD_LAST^#
359360

360361
// KEYWORD_LAST-DAG: Keyword/None: available[#Declaration Attribute#]; name=available{{$}}
362+
// KEYWORD_LAST-DAG: Keyword/None: freestanding[#Declaration Attribute#]; name=freestanding{{$}}
361363
// KEYWORD_LAST-DAG: Keyword/None: objc[#Declaration Attribute#]; name=objc{{$}}
362364
// KEYWORD_LAST-DAG: Keyword/None: dynamicCallable[#Declaration Attribute#]; name=dynamicCallable
363365
// KEYWORD_LAST-DAG: Keyword/None: main[#Declaration Attribute#]; name=main

0 commit comments

Comments
 (0)