提交 66b01b34 编写于 作者: K Kevin Pilch-Bisson

Merge pull request #5719 from Pilchie/Fix130910-WrappingOfBraces

Fix wrapping of single line members
......@@ -178,6 +178,13 @@ protected void AddBraceSuppressOperations(List<SuppressOperation> list, SyntaxNo
var firstTokenOfNode = node.GetFirstToken(includeZeroWidth: true);
var memberDeclNode = node as MemberDeclarationSyntax;
if (memberDeclNode != null)
{
var firstAndLastTokens = memberDeclNode.GetFirstAndLastMemberDeclarationTokensAfterAttributes();
firstTokenOfNode = firstAndLastTokens.Item1;
}
if (node.IsLambdaBodyBlock())
{
// include lambda itself.
......@@ -203,7 +210,7 @@ protected void AddBraceSuppressOperations(List<SuppressOperation> list, SyntaxNo
// this construct in the mind of the user.
//
// However, say the user hits semicolon, then hits enter, then types a close curly.
// In this scenario we woudl actually want the get-accessor to be formatted over multiple
// In this scenario we would actually want the get-accessor to be formatted over multiple
// lines. The difference here is that because the user just hit close-curly here we can
// consider it as being part of the closest construct and we can consider its placement
// when deciding if the construct is on a single line.
......
......@@ -56,12 +56,6 @@ public override void AddSuppressOperations(List<SuppressOperation> list, SyntaxN
}
}
var memberDeclNode = node as MemberDeclarationSyntax;
if (memberDeclNode != null)
{
return memberDeclNode.GetFirstAndLastMemberDeclarationTokensAfterAttributes();
}
var switchSection = node as SwitchSectionSyntax;
if (switchSection != null)
{
......
......@@ -1250,8 +1250,7 @@ public void TestWrappingNonDefault_FormatStatmtMethDecl()
AssertFormat(@"class Class5
{
delegate void Del(int x);
public int Age
{ get { int age = 0; return age; } }
public int Age { get { int age = 0; return age; } }
public int Age2
{
get { int age2 = 0; return age2; }
......@@ -1278,8 +1277,7 @@ void bar()
Del d = delegate (int k)
{ Console.WriteLine(); Console.WriteLine(); };
}
void foo()
{ int y = 0; int z = 0; }
void foo() { int y = 0; int z = 0; }
}
class foo
{
......@@ -6537,5 +6535,26 @@ void M()
AssertFormat(code, code);
}
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
[WorkItem(1711675, "https://connect.microsoft.com/VisualStudio/feedback/details/1711675/autoformatting-issues")]
public void SingleLinePropertiesPreservedWithLeaveStatementsAndMembersOnSingleLineFalse()
{
var changedOptionSet = new Dictionary<OptionKey, object>
{
{ CSharpFormattingOptions.WrappingPreserveSingleLine, true },
{ CSharpFormattingOptions.WrappingKeepStatementsOnSingleLine, false},
};
AssertFormat(@"
class C
{
string Name { get; set; }
}", @"
class C
{
string Name { get ; set ; }
}", changedOptionSet: changedOptionSet);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册