diff --git a/src/EditorFeatures/CSharpTest2/Recommendations/ReturnKeywordRecommenderTests.cs b/src/EditorFeatures/CSharpTest2/Recommendations/ReturnKeywordRecommenderTests.cs index d05e69eeee1f7..246dd11b1bd54 100644 --- a/src/EditorFeatures/CSharpTest2/Recommendations/ReturnKeywordRecommenderTests.cs +++ b/src/EditorFeatures/CSharpTest2/Recommendations/ReturnKeywordRecommenderTests.cs @@ -305,20 +305,20 @@ void Goo([$$ """); } - [Fact] - public async Task TestNotInPropertyAttribute() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71200")] + public async Task TestInPropertyAttribute() { - await VerifyAbsenceAsync( + await VerifyKeywordAsync( """ class C { int Goo { [$$ """); } - [Fact] - public async Task TestNotInEventAttribute() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71200")] + public async Task TestInEventAttribute() { - await VerifyAbsenceAsync( + await VerifyKeywordAsync( """ class C { event Action Goo { [$$ diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReturnKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReturnKeywordRecommender.cs index ac2ad5c246edd..6528bbdef7421 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReturnKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReturnKeywordRecommender.cs @@ -4,6 +4,7 @@ using System.Threading; using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Utilities; using Microsoft.CodeAnalysis.Shared.Extensions; @@ -30,7 +31,16 @@ private static bool IsAttributeContext(CSharpSyntaxContext context, Cancellation return context.IsMemberAttributeContext(SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations, cancellationToken) || (context.SyntaxTree.IsScript() && context.IsTypeAttributeContext(cancellationToken)) || - context.IsStatementAttributeContext(); + context.IsStatementAttributeContext() || + IsAccessorAttributeContext(); + + bool IsAccessorAttributeContext() + { + var token = context.TargetToken; + return token.Kind() == SyntaxKind.OpenBracketToken && + token.Parent is AttributeListSyntax && + token.Parent.Parent is AccessorDeclarationSyntax; + } } } }