Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't recommend readonly after readonly #72394

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 $$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
Loading