提交 3b5194e0 编写于 作者: Y Yair Halberstadt 提交者: Rikki Gibson

intellisense should suggest event after readonly in a struct member declaration (#35234)

* intellisense should suggest event after writing readonly in a struct member declaration.

* Avoid repetition of keywords in EventKeywordRecommender
上级 e5d15bb3
...@@ -378,5 +378,41 @@ class C ...@@ -378,5 +378,41 @@ class C
await VerifyItemExistsAsync(text, "private"); await VerifyItemExistsAsync(text, "private");
} }
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(34774, "https://github.com/dotnet/roslyn/issues/34774")]
public async Task DontSuggestEventAfterReadonlyInClass()
{
var markup =
@"class C {
readonly $$
}
";
await VerifyItemIsAbsentAsync(markup, "event");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(34774, "https://github.com/dotnet/roslyn/issues/34774")]
public async Task DontSuggestEventAfterReadonlyInInterface()
{
var markup =
@"interface C {
readonly $$
}
";
await VerifyItemIsAbsentAsync(markup, "event");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(34774, "https://github.com/dotnet/roslyn/issues/34774")]
public async Task SuggestEventAfterReadonlyInStruct()
{
var markup =
@"struct C {
readonly $$
}
";
await VerifyItemExistsAsync(markup, "event");
}
} }
} }
...@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders ...@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders
{ {
internal class EventKeywordRecommender : AbstractSyntacticSingleKeywordRecommender internal class EventKeywordRecommender : AbstractSyntacticSingleKeywordRecommender
{ {
private static readonly ISet<SyntaxKind> s_validModifiers = new HashSet<SyntaxKind>(SyntaxFacts.EqualityComparer) private static readonly ISet<SyntaxKind> s_validClassModifiers = new HashSet<SyntaxKind>(SyntaxFacts.EqualityComparer)
{ {
SyntaxKind.NewKeyword, SyntaxKind.NewKeyword,
SyntaxKind.PublicKeyword, SyntaxKind.PublicKeyword,
...@@ -25,6 +25,11 @@ internal class EventKeywordRecommender : AbstractSyntacticSingleKeywordRecommend ...@@ -25,6 +25,11 @@ internal class EventKeywordRecommender : AbstractSyntacticSingleKeywordRecommend
SyntaxKind.UnsafeKeyword SyntaxKind.UnsafeKeyword
}; };
private static readonly ISet<SyntaxKind> s_validStructModifiers = new HashSet<SyntaxKind>(s_validClassModifiers, SyntaxFacts.EqualityComparer)
{
SyntaxKind.ReadOnlyKeyword,
};
public EventKeywordRecommender() public EventKeywordRecommender()
: base(SyntaxKind.EventKeyword) : base(SyntaxKind.EventKeyword)
{ {
...@@ -36,7 +41,8 @@ protected override bool IsValidContext(int position, CSharpSyntaxContext context ...@@ -36,7 +41,8 @@ protected override bool IsValidContext(int position, CSharpSyntaxContext context
return return
context.IsGlobalStatementContext || context.IsGlobalStatementContext ||
syntaxTree.IsGlobalMemberDeclarationContext(position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) || syntaxTree.IsGlobalMemberDeclarationContext(position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
context.IsMemberDeclarationContext(validModifiers: s_validModifiers, validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken) || context.IsMemberDeclarationContext(validModifiers: s_validClassModifiers, validTypeDeclarations: SyntaxKindSet.ClassInterfaceTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken) ||
context.IsMemberDeclarationContext(validModifiers: s_validStructModifiers, validTypeDeclarations: SyntaxKindSet.StructOnlyTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken) ||
context.IsMemberAttributeContext(SyntaxKindSet.ClassInterfaceStructTypeDeclarations, cancellationToken); context.IsMemberAttributeContext(SyntaxKindSet.ClassInterfaceStructTypeDeclarations, cancellationToken);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册