diff --git a/src/EditorFeatures/CSharpTest2/Recommendations/ReadOnlyKeywordRecommenderTests.cs b/src/EditorFeatures/CSharpTest2/Recommendations/ReadOnlyKeywordRecommenderTests.cs index 059a0032eafe7..801d5f9f721c8 100644 --- a/src/EditorFeatures/CSharpTest2/Recommendations/ReadOnlyKeywordRecommenderTests.cs +++ b/src/EditorFeatures/CSharpTest2/Recommendations/ReadOnlyKeywordRecommenderTests.cs @@ -298,8 +298,8 @@ class C { } [Fact] - public async Task TestAfterPartial() - => await VerifyKeywordAsync(@"partial $$"); + public async Task TestNotAfterPartial() + => await VerifyAbsenceAsync(@"partial $$"); [Fact] public async Task TestAfterAbstract() @@ -437,9 +437,29 @@ class C { } [Fact] - public async Task TestAfterReadOnly() + public async Task TestNotAfterPublicReadOnly() { - await VerifyKeywordAsync( + await VerifyAbsenceAsync( + """ + class C { + public readonly $$ + """); + } + + [Fact] + public async Task TestNotAfterReadOnlyPartial() + { + await VerifyAbsenceAsync( + """ + class C { + readonly partial $$ + """); + } + + [Fact] + public async Task TestNotAfterReadOnly() + { + await VerifyAbsenceAsync( """ class C { readonly $$ diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReadOnlyKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReadOnlyKeywordRecommender.cs index 825d5186723d7..074bcc4111aac 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReadOnlyKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReadOnlyKeywordRecommender.cs @@ -3,9 +3,11 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Linq; using System.Threading; using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; using Microsoft.CodeAnalysis.CSharp.Utilities; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders; @@ -50,8 +52,8 @@ private static bool IsRefReadOnlyContext(CSharpSyntaxContext context) private static bool IsValidContextForType(CSharpSyntaxContext context, CancellationToken cancellationToken) { - return context.IsTypeDeclarationContext(validModifiers: SyntaxKindSet.AllTypeModifiers, - validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations, canBePartial: true, cancellationToken); + return context.IsTypeDeclarationContext(validModifiers: SyntaxKindSet.AllTypeModifiers.Except([SyntaxKind.ReadOnlyKeyword]).ToSet(), + validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations, canBePartial: false, cancellationToken); } private static bool IsStructAccessorContext(CSharpSyntaxContext context)