[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:
Alex Hoppen
2022-05-05 20:39:52 +02:00
parent 2f0ae44876
commit df605d479d
7 changed files with 209 additions and 24 deletions

View File

@@ -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.