Skip to content

[IDE] Complete nonisolated, unowned, and access control attribute parameter #79974

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 @@ -612,7 +612,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {

void getAttributeDeclCompletions(bool IsInSil, std::optional<DeclKind> DK);

void getAttributeDeclParamCompletions(CustomSyntaxAttributeKind AttrKind,
void getAttributeDeclParamCompletions(ParameterizedDeclAttributeKind AttrKind,
int ParamIndex, bool HasLabel);

void getTypeAttributeKeywordCompletions(CompletionKind completionKind);
Expand Down
11 changes: 7 additions & 4 deletions include/swift/Parse/IDEInspectionCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ enum class ObjCSelectorContext {
SetterSelector
};

/// Attributes that have syntax which can't be modelled using a function call.
/// This can't be \c DeclAttrKind because '@freestandig' and '@attached' have
/// Parameterized attributes that have code completion.
/// This can't be \c DeclAttrKind because '@freestanding' and '@attached' have
/// the same attribute kind but take different macro roles as arguemnts.
enum class CustomSyntaxAttributeKind {
enum class ParameterizedDeclAttributeKind {
AccessControl,
Nonisolated,
Unowned,
Available,
FreestandingMacro,
AttachedMacro,
Expand Down Expand Up @@ -228,7 +231,7 @@ class CodeCompletionCallbacks {
/// @available.
/// If `HasLabel` is `true`, then the argument already has a label specified,
/// e.g. we're completing after `names: ` in a macro declaration.
virtual void completeDeclAttrParam(CustomSyntaxAttributeKind DK, int Index,
virtual void completeDeclAttrParam(ParameterizedDeclAttributeKind DK, int Index,
bool HasLabel){};

/// Complete 'async' and 'throws' at effects specifier position.
Expand Down
6 changes: 3 additions & 3 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks,
SourceLoc DotLoc;
TypeLoc ParsedTypeLoc;
DeclContext *CurDeclContext = nullptr;
CustomSyntaxAttributeKind AttrKind;
ParameterizedDeclAttributeKind AttrKind;

/// When the code completion token occurs in a custom attribute, the attribute
/// it occurs in. Used so we can complete inside the attribute even if it's
Expand Down Expand Up @@ -272,7 +272,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks,
void completeCaseStmtKeyword() override;
void completeCaseStmtBeginning(CodeCompletionExpr *E) override;
void completeDeclAttrBeginning(bool Sil, bool isIndependent) override;
void completeDeclAttrParam(CustomSyntaxAttributeKind DK, int Index,
void completeDeclAttrParam(ParameterizedDeclAttributeKind DK, int Index,
bool HasLabel) override;
void completeEffectsSpecifier(bool hasAsync, bool hasThrows) override;
void completeInPrecedenceGroup(
Expand Down Expand Up @@ -460,7 +460,7 @@ void CodeCompletionCallbacksImpl::completeTypeSimpleBeginning() {
}

void CodeCompletionCallbacksImpl::completeDeclAttrParam(
CustomSyntaxAttributeKind DK, int Index, bool HasLabel) {
ParameterizedDeclAttributeKind DK, int Index, bool HasLabel) {
Kind = CompletionKind::AttributeDeclParen;
AttrKind = DK;
AttrParamIndex = Index;
Expand Down
26 changes: 18 additions & 8 deletions lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3103,9 +3103,19 @@ void CompletionLookup::getAttributeDeclCompletions(bool IsInSil,
}

void CompletionLookup::getAttributeDeclParamCompletions(
CustomSyntaxAttributeKind AttrKind, int ParamIndex, bool HasLabel) {
ParameterizedDeclAttributeKind AttrKind, int ParamIndex, bool HasLabel) {
switch (AttrKind) {
case CustomSyntaxAttributeKind::Available:
case ParameterizedDeclAttributeKind::Unowned:
addDeclAttrParamKeyword("safe", /*Parameters=*/{}, "", false);
addDeclAttrParamKeyword("unsafe", /*Parameters=*/{}, "", false);
break;
case ParameterizedDeclAttributeKind::Nonisolated:
addDeclAttrParamKeyword("unsafe", /*Parameters=*/{}, "", false);
break;
case ParameterizedDeclAttributeKind::AccessControl:
addDeclAttrParamKeyword("set", /*Parameters=*/{}, "", false);
break;
case ParameterizedDeclAttributeKind::Available:
if (ParamIndex == 0) {
addDeclAttrParamKeyword("*", /*Parameters=*/{}, "Platform", false);

Expand All @@ -3126,15 +3136,15 @@ void CompletionLookup::getAttributeDeclParamCompletions(
"Specify version number", true);
}
break;
case CustomSyntaxAttributeKind::FreestandingMacro:
case CustomSyntaxAttributeKind::AttachedMacro:
case ParameterizedDeclAttributeKind::FreestandingMacro:
case ParameterizedDeclAttributeKind::AttachedMacro:
switch (ParamIndex) {
case 0:
for (auto role : getAllMacroRoles()) {
bool isRoleSupported = isMacroSupported(role, Ctx);
if (AttrKind == CustomSyntaxAttributeKind::FreestandingMacro) {
if (AttrKind == ParameterizedDeclAttributeKind::FreestandingMacro) {
isRoleSupported &= isFreestandingMacro(role);
} else if (AttrKind == CustomSyntaxAttributeKind::AttachedMacro) {
} else if (AttrKind == ParameterizedDeclAttributeKind::AttachedMacro) {
isRoleSupported &= isAttachedMacro(role);
}
if (isRoleSupported) {
Expand Down Expand Up @@ -3162,7 +3172,7 @@ void CompletionLookup::getAttributeDeclParamCompletions(
break;
}
break;
case CustomSyntaxAttributeKind::StorageRestrictions: {
case ParameterizedDeclAttributeKind::StorageRestrictions: {
bool suggestInitializesLabel = false;
bool suggestAccessesLabel = false;
bool suggestArgument = false;
Expand Down Expand Up @@ -3295,7 +3305,7 @@ void CompletionLookup::getPrecedenceGroupCompletions(
void CompletionLookup::getPoundAvailablePlatformCompletions() {

// The platform names should be identical to those in @available.
getAttributeDeclParamCompletions(CustomSyntaxAttributeKind::Available, 0,
getAttributeDeclParamCompletions(ParameterizedDeclAttributeKind::Available, 0,
/*HasLabel=*/false);
}

Expand Down
Loading