mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Mark types that can’t be used as attributes as having an invalid type relation when used after '@'
When completing after `@`, record what kind of attributes are applicable here (property wrapper, result builder, global actor), mark types that are marked as property wrapper etc. as having a 'Convertible' type relation and mark all other types as having an invalid type relation. rdar://78239501
This commit is contained in:
@@ -1695,6 +1695,35 @@ void CodeCompletionCallbacksImpl::doneParsing() {
|
||||
|
||||
case CompletionKind::AttributeBegin: {
|
||||
Lookup.getAttributeDeclCompletions(IsInSil, AttTargetDK);
|
||||
OptionSet<CustomAttributeKind> ExpectedCustomAttributeKinds;
|
||||
if (AttTargetDK) {
|
||||
switch (*AttTargetDK) {
|
||||
case DeclKind::Var:
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::GlobalActor;
|
||||
LLVM_FALLTHROUGH;
|
||||
case DeclKind::Param:
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::ResultBuilder;
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::PropertyWrapper;
|
||||
break;
|
||||
case DeclKind::Func:
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::ResultBuilder;
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::GlobalActor;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ExpectedCustomAttributeKinds) {
|
||||
// If we don't know on which decl kind we are completing, suggest all
|
||||
// attribute kinds.
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::PropertyWrapper;
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::ResultBuilder;
|
||||
ExpectedCustomAttributeKinds |= CustomAttributeKind::GlobalActor;
|
||||
}
|
||||
Lookup.setExpectedTypes(/*Types=*/{},
|
||||
/*isImplicitSingleExpressionReturn=*/false,
|
||||
/*preferNonVoid=*/false,
|
||||
ExpectedCustomAttributeKinds);
|
||||
|
||||
// TypeName at attribute position after '@'.
|
||||
// - VarDecl: Property Wrappers.
|
||||
|
||||
Reference in New Issue
Block a user