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

Offer 'in' as completion in operator #24089

Merged
merged 1 commit into from
Jan 9, 2018
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 @@ -488,6 +488,30 @@ class C {
public C(object arg1) : this(arg1, $$");
}

[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(24079, "https://github.com/dotnet/roslyn/issues/24079")]
public async Task TestInAsParameterModifierInConversionOperators()
{
await VerifyKeywordAsync(@"
class Program
{
public static explicit operator double($$) { }
}");
}

[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(24079, "https://github.com/dotnet/roslyn/issues/24079")]
public async Task TestInAsParameterModifierInBinaryOperators()
{
await VerifyKeywordAsync(@"
class Program
{
public static Program operator +($$) { }
}");
}

[Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)]
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestInConstructorCallFirstArgumentModifier()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ await VerifyKeywordAsync(
}

[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(24079, "https://github.com/dotnet/roslyn/issues/24079")]
public async Task TestNotAfterOperator()
{
await VerifyAbsenceAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override bool IsValidContext(int position, CSharpSyntaxContext context
IsValidContextInForEachClause(context) ||
IsValidContextInFromClause(context, cancellationToken) ||
IsValidContextInJoinClause(context, cancellationToken) ||
syntaxTree.IsParameterModifierContext(position, context.LeftToken, cancellationToken) ||
syntaxTree.IsParameterModifierContext(position, context.LeftToken, cancellationToken, includeOperators: true) ||
syntaxTree.IsAnonymousMethodParameterModifierContext(position, context.LeftToken, cancellationToken) ||
syntaxTree.IsPossibleLambdaParameterModifierContext(position, context.LeftToken, cancellationToken) ||
context.TargetToken.IsConstructorOrMethodParameterArgumentContext() ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
// 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 Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery
{
internal static class SyntaxNodeExtensions
{
public static bool IsDelegateOrConstructorOrLocalFunctionOrMethodParameterList(this SyntaxNode node)
public static bool IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList(this SyntaxNode node, bool includeOperators)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the extra parameter? What's the consequence of just returning true for all of the operators as well all of the time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, it's not terrible if we offer keywords even when not always applicable. That's still much better than not offering it. Then, we could just make this cod really simple. Basically: "offer these things if it's in a parameter list", even if that allows some things when not applicable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The impact is offering out and ref in places where they are not applicable.
Sure. I'll remove the parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... at this point i think it's fine to offer in all argument cases. It's unlikely anyone would notice. And the worst impact is they type something that the compiler then tells you is not valid.

{
if (!node.IsKind(SyntaxKind.ParameterList))
{
return false;
}

return
node.IsParentKind(SyntaxKind.MethodDeclaration) ||
if (node.IsParentKind(SyntaxKind.MethodDeclaration) ||
node.IsParentKind(SyntaxKind.LocalFunctionStatement) ||
node.IsParentKind(SyntaxKind.ConstructorDeclaration) ||
node.IsParentKind(SyntaxKind.DelegateDeclaration);
node.IsParentKind(SyntaxKind.DelegateDeclaration))
{
return true;
}

if (includeOperators)
{
return
node.IsParentKind(SyntaxKind.OperatorDeclaration) ||
node.IsParentKind(SyntaxKind.ConversionOperatorDeclaration);
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ public static bool IsParameterModifierContext(
int position,
SyntaxToken tokenOnLeftOfPosition,
CancellationToken cancellationToken,
bool includeOperators = false,
bool isThisKeyword = false)
{
// cases:
Expand All @@ -988,13 +989,13 @@ public static bool IsParameterModifierContext(
token = token.GetPreviousTokenIfTouchingWord(position);

if (token.IsKind(SyntaxKind.OpenParenToken) &&
token.Parent.IsDelegateOrConstructorOrLocalFunctionOrMethodParameterList())
token.Parent.IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList(includeOperators))
{
return true;
}

if (token.IsKind(SyntaxKind.CommaToken) &&
token.Parent.IsDelegateOrConstructorOrLocalFunctionOrMethodParameterList())
token.Parent.IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList(includeOperators))
{
if (isThisKeyword)
{
Expand All @@ -1010,7 +1011,7 @@ public static bool IsParameterModifierContext(
if (token.IsKind(SyntaxKind.CloseBracketToken) &&
token.Parent.IsKind(SyntaxKind.AttributeList) &&
token.Parent.IsParentKind(SyntaxKind.Parameter) &&
token.Parent.GetParent().GetParent().IsDelegateOrConstructorOrLocalFunctionOrMethodParameterList())
token.Parent.GetParent().GetParent().IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList(includeOperators))
{
if (isThisKeyword)
{
Expand All @@ -1026,7 +1027,7 @@ public static bool IsParameterModifierContext(

if (isThisKeyword &&
(token.IsKind(SyntaxKind.RefKeyword) || token.IsKind(SyntaxKind.InKeyword)) &&
token.Parent.GetParent().IsDelegateOrConstructorOrLocalFunctionOrMethodParameterList())
token.Parent.GetParent().IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList(includeOperators))
{
var parameter = token.GetAncestor<ParameterSyntax>();
var parameterList = parameter.GetAncestorOrThis<ParameterListSyntax>();
Expand Down