Skip to content

Commit

Permalink
IDE feedback (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Nov 8, 2016
1 parent 7e4ea6e commit d39e75e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1608,13 +1608,13 @@ internal static string GetStatementDisplayNameImpl(SyntaxNode node)
return CSharpFeaturesResources.deconstruction;

case SyntaxKind.SimpleAssignmentExpression:
if (IsDeconstruction((AssignmentExpressionSyntax)node))
if (((AssignmentExpressionSyntax)node).IsDeconstruction())
{
return CSharpFeaturesResources.deconstruction;
}
else
{
goto default;
throw ExceptionUtilities.UnexpectedValue(node.Kind());
}

case SyntaxKind.TupleType:
Expand Down Expand Up @@ -3119,18 +3119,12 @@ private static bool IsUnsupportedCSharp7EnCNode(SyntaxNode n)
case SyntaxKind.DeclarationPattern:
return true;
case SyntaxKind.SimpleAssignmentExpression:
return IsDeconstruction((AssignmentExpressionSyntax)n);
return ((AssignmentExpressionSyntax)n).IsDeconstruction();
default:
return false;
}
}

private static bool IsDeconstruction(AssignmentExpressionSyntax assignment)
{
return assignment.Left.Kind() == SyntaxKind.TupleExpression ||
assignment.Left.Kind() == SyntaxKind.DeclarationExpression;
}

private void ReportRudeEditsForCheckedStatements(
List<RudeEditDiagnostic> diagnostics,
SyntaxNode oldActiveStatement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ public override void VisitSwitchStatement(SwitchStatementSyntax node)
case SyntaxKind.TupleExpression:
{
var t = (TupleExpressionSyntax)component;
foreach (ArgumentSyntax a in t.Arguments) AddVariableExpressions(a.Expression, expressions);
foreach (ArgumentSyntax a in t.Arguments)
{
AddVariableExpressions(a.Expression, expressions);
}

break;
}
case SyntaxKind.DeclarationExpression:
Expand Down
1 change: 1 addition & 0 deletions src/Workspaces/CSharp/Portable/CSharpWorkspace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Compile Include="Composition\CSharpWorkspaceFeatures.cs" />
<Compile Include="Execution\CSharpOptionsSerializationService.cs" />
<Compile Include="Extensions\ArrowExpressionClauseSyntaxExtensions.cs" />
<Compile Include="Extensions\AssignmentExpressionSyntaxExtensions.cs" />
<Compile Include="Extensions\BlockSyntaxExtensions.cs" />
<Compile Include="Extensions\SemanticModelExtensions.cs" />
<Compile Include="LanguageServices\CSharpCommandLineParserService.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.CSharp.Extensions
{
internal static class AssignmentExpressionSyntaxExtensions
{
internal static bool IsDeconstruction(this AssignmentExpressionSyntax assignment)
{
var left = assignment.Left;
return assignment.Kind() == SyntaxKind.SimpleAssignmentExpression &&
assignment.OperatorToken.Kind() == SyntaxKind.EqualsToken &&
(left.Kind() == SyntaxKind.TupleExpression || left.Kind() == SyntaxKind.DeclarationExpression);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ private static bool CanBindToken(SyntaxToken token)
{
var decl = (DeclarationExpressionSyntax)current;
var name = decl.Designation as SingleVariableDesignationSyntax;
if (name == null) break;
if (name == null)
{
break;
}

return name.Identifier.ValueText.ToCamelCase();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,9 @@ private IEnumerable<TypeInferenceInfo> InferTypeInBinaryOrAssignmentExpression(E
return SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(this.Compilation.GetSpecialType(SpecialType.System_Boolean)));
}

// Infer type for deconstruction declaration
if (operatorToken.Kind() == SyntaxKind.EqualsToken &&
(left.Kind() == SyntaxKind.TupleExpression || left.Kind() == SyntaxKind.DeclarationExpression))
// Infer type for deconstruction
if (binop.Kind() == SyntaxKind.SimpleAssignmentExpression &&
((AssignmentExpressionSyntax)binop).IsDeconstruction())
{
return InferTypeInVariableComponentAssignment(left);
}
Expand Down

0 comments on commit d39e75e

Please sign in to comment.