Skip to content

Commit 829e03c

Browse files
authored
Merge pull request #79974 from a7medev/feature/complete-single-option-decl-attrs
2 parents 85e4685 + c74e271 commit 829e03c

File tree

8 files changed

+155
-66
lines changed

8 files changed

+155
-66
lines changed

include/swift/IDE/CompletionLookup.h

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

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

615-
void getAttributeDeclParamCompletions(CustomSyntaxAttributeKind AttrKind,
615+
void getAttributeDeclParamCompletions(ParameterizedDeclAttributeKind AttrKind,
616616
int ParamIndex, bool HasLabel);
617617

618618
void getTypeAttributeKeywordCompletions(CompletionKind completionKind);

include/swift/Parse/IDEInspectionCallbacks.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ enum class ObjCSelectorContext {
2929
SetterSelector
3030
};
3131

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

234237
/// Complete 'async' and 'throws' at effects specifier position.

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks,
114114
SourceLoc DotLoc;
115115
TypeLoc ParsedTypeLoc;
116116
DeclContext *CurDeclContext = nullptr;
117-
CustomSyntaxAttributeKind AttrKind;
117+
ParameterizedDeclAttributeKind AttrKind;
118118

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

462462
void CodeCompletionCallbacksImpl::completeDeclAttrParam(
463-
CustomSyntaxAttributeKind DK, int Index, bool HasLabel) {
463+
ParameterizedDeclAttributeKind DK, int Index, bool HasLabel) {
464464
Kind = CompletionKind::AttributeDeclParen;
465465
AttrKind = DK;
466466
AttrParamIndex = Index;

lib/IDE/CompletionLookup.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,9 +3103,19 @@ void CompletionLookup::getAttributeDeclCompletions(bool IsInSil,
31033103
}
31043104

31053105
void CompletionLookup::getAttributeDeclParamCompletions(
3106-
CustomSyntaxAttributeKind AttrKind, int ParamIndex, bool HasLabel) {
3106+
ParameterizedDeclAttributeKind AttrKind, int ParamIndex, bool HasLabel) {
31073107
switch (AttrKind) {
3108-
case CustomSyntaxAttributeKind::Available:
3108+
case ParameterizedDeclAttributeKind::Unowned:
3109+
addDeclAttrParamKeyword("safe", /*Parameters=*/{}, "", false);
3110+
addDeclAttrParamKeyword("unsafe", /*Parameters=*/{}, "", false);
3111+
break;
3112+
case ParameterizedDeclAttributeKind::Nonisolated:
3113+
addDeclAttrParamKeyword("unsafe", /*Parameters=*/{}, "", false);
3114+
break;
3115+
case ParameterizedDeclAttributeKind::AccessControl:
3116+
addDeclAttrParamKeyword("set", /*Parameters=*/{}, "", false);
3117+
break;
3118+
case ParameterizedDeclAttributeKind::Available:
31093119
if (ParamIndex == 0) {
31103120
addDeclAttrParamKeyword("*", /*Parameters=*/{}, "Platform", false);
31113121

@@ -3126,15 +3136,15 @@ void CompletionLookup::getAttributeDeclParamCompletions(
31263136
"Specify version number", true);
31273137
}
31283138
break;
3129-
case CustomSyntaxAttributeKind::FreestandingMacro:
3130-
case CustomSyntaxAttributeKind::AttachedMacro:
3139+
case ParameterizedDeclAttributeKind::FreestandingMacro:
3140+
case ParameterizedDeclAttributeKind::AttachedMacro:
31313141
switch (ParamIndex) {
31323142
case 0:
31333143
for (auto role : getAllMacroRoles()) {
31343144
bool isRoleSupported = isMacroSupported(role, Ctx);
3135-
if (AttrKind == CustomSyntaxAttributeKind::FreestandingMacro) {
3145+
if (AttrKind == ParameterizedDeclAttributeKind::FreestandingMacro) {
31363146
isRoleSupported &= isFreestandingMacro(role);
3137-
} else if (AttrKind == CustomSyntaxAttributeKind::AttachedMacro) {
3147+
} else if (AttrKind == ParameterizedDeclAttributeKind::AttachedMacro) {
31383148
isRoleSupported &= isAttachedMacro(role);
31393149
}
31403150
if (isRoleSupported) {
@@ -3162,7 +3172,7 @@ void CompletionLookup::getAttributeDeclParamCompletions(
31623172
break;
31633173
}
31643174
break;
3165-
case CustomSyntaxAttributeKind::StorageRestrictions: {
3175+
case ParameterizedDeclAttributeKind::StorageRestrictions: {
31663176
bool suggestInitializesLabel = false;
31673177
bool suggestAccessesLabel = false;
31683178
bool suggestArgument = false;
@@ -3296,7 +3306,7 @@ void CompletionLookup::getPrecedenceGroupCompletions(
32963306
void CompletionLookup::getPoundAvailablePlatformCompletions() {
32973307

32983308
// The platform names should be identical to those in @available.
3299-
getAttributeDeclParamCompletions(CustomSyntaxAttributeKind::Available, 0,
3309+
getAttributeDeclParamCompletions(ParameterizedDeclAttributeKind::Available, 0,
33003310
/*HasLabel=*/false);
33013311
}
33023312

0 commit comments

Comments
 (0)