提交 51b5a8b0 编写于 作者: Š Šimon Koníček

Adding C# tests, fixing a bug

上级 25a7354d
......@@ -519,7 +519,7 @@ void M(bool a, bool b)
}
[Fact]
public async Task SplitWithStatementNoBlock()
public async Task SplitWithStatementWithoutBlock()
{
await TestInRegularAndScriptAsync(
@"class C
......@@ -628,7 +628,7 @@ void M(bool a, bool b)
}
[Fact]
public async Task SplitWithElseStatementNoBlock()
public async Task SplitWithElseStatementWithoutBlock()
{
await TestInRegularAndScriptAsync(
@"class C
......
......@@ -74,7 +74,7 @@ private async Task<Document> FixAsync(Document document, TextSpan span, ISyntaxF
private static bool IsFirstStatementOfIfStatement(
ISyntaxFactsService syntaxFacts, SyntaxNode statement, out TIfStatementSyntax ifStatement)
{
if (syntaxFacts.IsStatementContainer(statement.Parent) &&
if ((statement.Parent is TIfStatementSyntax || syntaxFacts.IsPureBlock(statement.Parent)) &&
syntaxFacts.GetStatementContainerStatements(statement.Parent).FirstOrDefault() == statement)
{
do
......@@ -87,7 +87,7 @@ private async Task<Document> FixAsync(Document document, TextSpan span, ISyntaxF
statement = statement.Parent;
}
while (syntaxFacts.IsStatementContainer(statement.Parent) &&
while ((statement.Parent is TIfStatementSyntax || syntaxFacts.IsPureBlock(statement.Parent)) &&
syntaxFacts.GetStatementContainerStatements(statement.Parent).TrySingleOrDefault() == statement);
}
......
......@@ -99,6 +99,7 @@ public static class Features
public const string CodeActionsMakeFieldReadonly = "CodeActions.MakeFieldReadonly";
public const string CodeActionsMakeMethodAsynchronous = "CodeActions.MakeMethodAsynchronous";
public const string CodeActionsMakeMethodSynchronous = "CodeActions.MakeMethodSynchronous";
public const string CodeActionsMergeNestedIfStatements = "CodeActions.MergeNestedIfStatements";
public const string CodeActionsMoveDeclarationNearReference = "CodeActions.MoveDeclarationNearReference";
public const string CodeActionsMoveToTopOfFile = "CodeActions.MoveToTopOfFile";
public const string CodeActionsMoveType = "CodeActions.MoveType";
......
......@@ -1897,6 +1897,9 @@ public SyntaxNode GetTypeOfVariableDeclarator(SyntaxNode node)
public SyntaxNode GetValueOfEqualsValueClause(SyntaxNode node)
=> ((EqualsValueClauseSyntax)node)?.Value;
public bool IsPureBlock(SyntaxNode node)
=> node.IsKind(SyntaxKind.Block);
public bool IsExecutableBlock(SyntaxNode node)
=> node.IsKind(SyntaxKind.Block, SyntaxKind.SwitchSection);
......
......@@ -288,6 +288,7 @@ internal interface ISyntaxFactsService : ILanguageService
bool IsTopLevelNodeWithMembers(SyntaxNode node);
bool HasIncompleteParentMember(SyntaxNode node);
bool IsPureBlock(SyntaxNode node);
bool IsExecutableBlock(SyntaxNode node);
SyntaxList<SyntaxNode> GetExecutableBlockStatements(SyntaxNode node);
SyntaxNode FindInnermostCommonExecutableBlock(IEnumerable<SyntaxNode> nodes);
......
......@@ -1816,6 +1816,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return DirectCast(node, EqualsValueSyntax).Value
End Function
Public Function IsPureBlock(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsPureBlock
' VB has no equivalent of curly braces.
Return False
End Function
Public Function IsExecutableBlock(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsExecutableBlock
Return node.IsExecutableBlock()
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册