提交 7f93cad6 编写于 作者: O Omar Tawfik

In/RefReadOnly tokens in completion service for signatures

上级 95911739
......@@ -493,5 +493,111 @@ public static void Test()
await VerifyItemExistsAsync(code, "in");
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task RefReadOnlyWillPopUpInMethodReturnTypes()
{
var code = @"
class Program
{
public ref $$ int Test()
{
return ref x;
}
}";
await VerifyItemExistsAsync(code, "readonly");
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task RefReadOnlyWillPopUpInGlobalMemberDeclaration()
{
var code = @"
public ref $$ ";
await VerifyItemExistsAsync(code, "readonly", sourceCodeKind: SourceCodeKind.Script);
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task RefReadOnlyWillPopUpInDelegateReturnType()
{
var code = @"
public delegate ref $$ int Delegate();
class Program
{
}";
await VerifyItemExistsAsync(code, "readonly");
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task RefReadOnlyWillPopUpInMemberDeclaration()
{
var code = @"
class Program
{
public ref $$ int Test { get; set; }
}";
await VerifyItemExistsAsync(code, "readonly");
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task InWillPopUpInMethodReturnTypes()
{
var code = @"
class Program
{
public $$ int Test()
{
return ref x;
}
}";
await VerifyItemExistsAsync(code, "in");
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task InWillPopUpInGlobalMemberDeclaration()
{
var code = @"
public $$ ";
await VerifyItemExistsAsync(code, "in", sourceCodeKind: SourceCodeKind.Script);
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task InWillPopUpInDelegateReturnType()
{
var code = @"
public delegate $$ int Delegate();
class Program
{
}";
await VerifyItemExistsAsync(code, "in");
}
[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadonlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task InWillPopUpInMemberDeclaration()
{
var code = @"
class Program
{
public $$ int Test { get; set; }
}";
await VerifyItemExistsAsync(code, "in");
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Utilities;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders
......@@ -15,6 +17,46 @@ public InKeywordRecommender()
{
}
/// <summary>
/// Same as <see cref="SyntaxKindSet.AllMemberModifiers"/> with in specific exclusions
/// </summary>
private static readonly ISet<SyntaxKind> InMemberModifiers = new HashSet<SyntaxKind>(SyntaxFacts.EqualityComparer)
{
SyntaxKind.AbstractKeyword,
// SyntaxKind.AsyncKeyword, // async methods cannot be in
SyntaxKind.ExternKeyword,
SyntaxKind.InternalKeyword,
SyntaxKind.NewKeyword,
SyntaxKind.OverrideKeyword,
SyntaxKind.PublicKeyword,
SyntaxKind.PrivateKeyword,
SyntaxKind.ProtectedKeyword,
// SyntaxKind.ReadOnlyKeyword, // fields cannot be in
SyntaxKind.SealedKeyword,
SyntaxKind.StaticKeyword,
SyntaxKind.UnsafeKeyword,
SyntaxKind.VirtualKeyword,
// SyntaxKind.VolatileKeyword, // fields cannot be in
};
/// <summary>
/// Same as <see cref="SyntaxKindSet.AllGlobalMemberModifiers"/> with in specific exclusions
/// </summary>
private static readonly ISet<SyntaxKind> InGlobalMemberModifiers = new HashSet<SyntaxKind>(SyntaxFacts.EqualityComparer)
{
// SyntaxKind.AsyncKeyword, // async methods cannot be in
SyntaxKind.ExternKeyword,
SyntaxKind.InternalKeyword,
SyntaxKind.NewKeyword,
SyntaxKind.OverrideKeyword,
SyntaxKind.PublicKeyword,
SyntaxKind.PrivateKeyword,
// SyntaxKind.ReadOnlyKeyword, // fields cannot be in
SyntaxKind.StaticKeyword,
SyntaxKind.UnsafeKeyword,
// SyntaxKind.VolatileKeyword, // fields cannot be in
};
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
......@@ -24,7 +66,14 @@ protected override bool IsValidContext(int position, CSharpSyntaxContext context
context.TargetToken.IsTypeParameterVarianceContext() ||
context.SyntaxTree.IsParameterModifierContext(position, context.LeftToken, cancellationToken) ||
context.SyntaxTree.IsAnonymousMethodParameterModifierContext(position, context.LeftToken, cancellationToken) ||
context.SyntaxTree.IsPossibleLambdaParameterModifierContext(position, context.LeftToken, cancellationToken);
context.SyntaxTree.IsPossibleLambdaParameterModifierContext(position, context.LeftToken, cancellationToken) ||
context.IsDelegateReturnTypeContext ||
context.SyntaxTree.IsGlobalMemberDeclarationContext(position, InGlobalMemberModifiers, cancellationToken) ||
context.IsMemberDeclarationContext(
validModifiers: InMemberModifiers,
validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructTypeDeclarations,
canBePartial: true,
cancellationToken: cancellationToken);
}
private bool IsValidContextInForEachClause(CSharpSyntaxContext context)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册