Skip to content

[5.9][CodeCompletion] Suggest freestanding after @ #65486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/IDE/CompletionLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {

static bool canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
bool IsConcurrencyEnabled,
Optional<DeclKind> DK);
Optional<DeclKind> DK, StringRef Name);

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

Expand Down
13 changes: 10 additions & 3 deletions lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,8 @@ void CompletionLookup::getGenericRequirementCompletions(

bool CompletionLookup::canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
bool IsConcurrencyEnabled,
Optional<DeclKind> DK) {
Optional<DeclKind> DK,
StringRef Name) {
if (DeclAttribute::isUserInaccessible(DAK))
return false;
if (DeclAttribute::isDeclModifier(DAK))
Expand All @@ -2979,6 +2980,11 @@ bool CompletionLookup::canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
return false;
if (!DK.has_value())
return true;
// Hide underscored attributes even if they are not marked as user
// inaccessible. This can happen for attributes that are an underscored
// variant of a user-accessible attribute (like @_backDeployed)
if (Name.empty() || Name[0] == '_')
return false;
return DeclAttribute::canAttributeAppearOnDeclKind(DAK, DK.value());
}

Expand All @@ -2997,9 +3003,10 @@ void CompletionLookup::getAttributeDeclCompletions(bool IsInSil,
}
bool IsConcurrencyEnabled = Ctx.LangOpts.EnableExperimentalConcurrency;
std::string Description = TargetName.str() + " Attribute";
#define DECL_ATTR_ALIAS(KEYWORD, NAME) DECL_ATTR(KEYWORD, NAME, 0, 0)
#define DECL_ATTR(KEYWORD, NAME, ...) \
if (canUseAttributeOnDecl(DAK_##NAME, IsInSil, IsConcurrencyEnabled, \
DK)) \
if (canUseAttributeOnDecl(DAK_##NAME, IsInSil, IsConcurrencyEnabled, DK, \
#KEYWORD)) \
addDeclAttrKeyword(#KEYWORD, Description);
#include "swift/AST/Attr.def"
}
Expand Down
2 changes: 2 additions & 0 deletions test/IDE/complete_decl_attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ struct _S {
// ON_MEMBER_LAST-DAG: Keyword/None: preconcurrency[#Declaration Attribute#]; name=preconcurrency
// ON_MEMBER_LAST-DAG: Keyword/None: runtimeMetadata[#Declaration Attribute#]; name=runtimeMetadata
// ON_MEMBER_LAST-DAG: Keyword/None: attached[#Declaration Attribute#]; name=attached
// ON_MEMBER_LAST-DAG: Keyword/None: freestanding[#Declaration Attribute#]; name=freestanding
// ON_MEMBER_LAST-NOT: Keyword
// ON_MEMBER_LAST-DAG: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
// ON_MEMBER_LAST-DAG: Decl[Struct]/CurrModule/TypeRelation[Convertible]: MyPropertyWrapper[#MyPropertyWrapper#]; name=MyPropertyWrapper
Expand Down Expand Up @@ -358,6 +359,7 @@ func dummy2() {}
@#^KEYWORD_LAST^#

// KEYWORD_LAST-DAG: Keyword/None: available[#Declaration Attribute#]; name=available{{$}}
// KEYWORD_LAST-DAG: Keyword/None: freestanding[#Declaration Attribute#]; name=freestanding{{$}}
// KEYWORD_LAST-DAG: Keyword/None: objc[#Declaration Attribute#]; name=objc{{$}}
// KEYWORD_LAST-DAG: Keyword/None: dynamicCallable[#Declaration Attribute#]; name=dynamicCallable
// KEYWORD_LAST-DAG: Keyword/None: main[#Declaration Attribute#]; name=main
Expand Down