提交 d2715bc9 编写于 作者: L Lillo

Add test TestBeforeAssemblyAttribute

上级 12dc267b
......@@ -119,13 +119,24 @@ public async Task TestInOuterAttribute()
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(362, "https://github.com/dotnet/roslyn/issues/362")]
public async Task TestOutOuterAttributeInNamespace()
public async Task TestBeforeAttributeNamespace()
{
await VerifyKeywordAsync(
@"[$$
namespace Goo {}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(362, "https://github.com/dotnet/roslyn/issues/362")]
public async Task TestBeforeAssemblyAttribute()
{
await VerifyKeywordAsync(
@"
[$$
[assembly: Whatever]
namespace Goo {}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestNotInOuterAttributeInNamespace()
{
......
......@@ -17,7 +17,7 @@ public AssemblyKeywordRecommender()
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
if (context.TargetToken.GetNextToken().Kind() == SyntaxKind.NamespaceKeyword || context.IsTypeAttributeContext(cancellationToken) )
if (context.TargetToken.IsBeforeNamespace()|| context.IsTypeAttributeContext(cancellationToken) )
{
var token = context.LeftToken;
var type = token.GetAncestor<MemberDeclarationSyntax>();
......
......@@ -5,7 +5,6 @@
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery
{
......@@ -671,5 +670,13 @@ public static bool IsMandatoryNamedParameterPosition(this SyntaxToken token)
return false;
}
public static bool IsBeforeNamespace(this SyntaxToken token)
{
// cases:
// | namespace Goo
// | [N] namespace Goo
return token.GetNextToken().Kind() == SyntaxKind.NamespaceKeyword;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册