提交 ee24f8e9 编写于 作者: S Sam Harwell

Only align trailing line comments

Fixes #16681
Fixes #38224
上级 bf47f1ee
......@@ -3920,16 +3920,16 @@ IEnumerable<int> M(IEnumerable<int> nums)
// 1
from/* 3 *//* 2 *//* 4 */x /* 5 */ in/* 6 */nums/* 7 */// 8
// 9
/* 10 */
/* 10 */
from/* 12 *//* 11 */int /* 13 */ y /* 14 */ in/* 15 */nums/* 16 *//* 17 */// 18
// 19
/*20 */
/*20 */
where/* 21 *//* 22 */x > 2/* 23 */// 24
/* 26 *//* 27 *//* 28 */
/* 26 *//* 27 *//* 28 */
select x * y/* 29 *//* 31 */// 32
/* 33 */// 34
/* 35 *//* 36 */// 30
/* 37 *//* 38 *//* 39*/// 40
/* 33 */// 34
/* 35 *//* 36 */// 30
/* 37 *//* 38 *//* 39*/// 40
;
}
}";
......@@ -3944,21 +3944,21 @@ class C
IEnumerable<int> M(IEnumerable<int> nums)
{
return nums /* 7 */.SelectMany(
// 1
/* 2 */// 25
/* 4 */x /* 5 */ => nums /* 16 */.Where(
/*20 *//* 21 */// 19
y =>
// 1
/* 2 */// 25
/* 4 */x /* 5 */ => nums /* 16 */.Where(
/*20 *//* 21 */// 19
y =>
/* 22 */x > 2/* 23 */// 24
).Select(
// 9
/* 10 *//* 11 *//* 13 */y /* 14 */ =>
).Select(
// 9
/* 10 *//* 11 *//* 13 */y /* 14 */ =>
/* 26 *//* 27 *//* 28 */x * y/* 29 *//* 31 */// 32
/* 33 */// 34
/* 35 *//* 36 */// 30
/* 37 *//* 38 *//* 39*/// 40
/* 12 *//* 15 *//* 17 */// 18
)/* 3 *//* 6 */// 8
/* 33 */// 34
/* 35 *//* 36 */// 30
/* 37 *//* 38 *//* 39*/// 40
/* 12 *//* 15 *//* 17 */// 18
)/* 3 *//* 6 */// 8
);
}
}";
......@@ -3995,11 +3995,11 @@ List<int> M(IEnumerable<int> nums)
{
/*29*/
return /*30*/ /* 1 *//* 2 *//* 3 *//* 4 */// 5
/*31*/
/*31*/
(
/* 6 */from/* 8 *//* 7 *//* 9 */x /* 10 */ in/* 11 */nums/* 12 */// 13
/* 14 */// 15
/* 16 *//* 17 */
/* 14 */// 15
/* 16 *//* 17 */
let y /* 18 */ = /* 19 */ x + 1/* 20 *///21
select y/* 24 *//*27*///28
).ToList()/* 22 *//* 23 *//* 25 *///26
......@@ -4042,10 +4042,10 @@ List<int> M(IEnumerable<int> nums)
{
/*23*/
return /*24*/ /* 1 *//* 2 *//* 3 *//* 4 */// 5
/*25*/
/*25*/
(
/* 14 */// 15
/* 6 */from/* 8 *//* 7 *//* 9 */x /* 10 */ in/* 11 */nums/* 12 */// 13
/* 14 */// 15
/* 6 */from/* 8 *//* 7 *//* 9 */x /* 10 */ in/* 11 */nums/* 12 */// 13
select x + 1/* 18 *//*21*///22
).ToList()/* 16 *//* 17 *//* 19 *///20
; //26
......@@ -4063,11 +4063,11 @@ List<int> M(IEnumerable<int> nums)
{
/*23*/
return /*24*/ /* 1 *//* 2 *//* 3 *//* 4 */// 5
/*25*/
/*25*/
(nums /* 12 */.Select(
/* 6 *//* 7 *//* 14 */// 15
/* 9 */x /* 10 */ => x + 1/* 18 *//*21*///22
/* 8 *//* 11 */// 13
/* 6 *//* 7 *//* 14 */// 15
/* 9 */x /* 10 */ => x + 1/* 18 *//*21*///22
/* 8 *//* 11 */// 13
)).ToList()/* 16 *//* 17 *//* 19 *///20
; //26
}
......@@ -4104,10 +4104,10 @@ int M(IEnumerable<int> nums)
{
/*21*/
return /*22*/ /* 1 *//* 2 *//* 3 *//* 4 */// 5
/*23*/
/*23*/
(
/* 14 */// 15
/* 6 */from/* 8 *//* 7 *//* 9 */x /* 10 */ in/* 11 */nums/* 12 */// 13
/* 14 */// 15
/* 6 */from/* 8 *//* 7 *//* 9 */x /* 10 */ in/* 11 */nums/* 12 */// 13
select x/* 10 *//*19*///20
).Count()/* 16 *//* 17 *///18
; //24
......@@ -4125,11 +4125,11 @@ int M(IEnumerable<int> nums)
{
/*21*/
return /*22*/ /* 1 *//* 2 *//* 3 *//* 4 */// 5
/*23*/
/*23*/
(nums /* 12 */.Select(
/* 6 *//* 7 *//* 14 */// 15
/* 9 */x /* 10 */ => x/* 10 *//*19*///20
/* 8 *//* 11 */// 13
/* 6 *//* 7 *//* 14 */// 15
/* 9 */x /* 10 */ => x/* 10 *//*19*///20
/* 8 *//* 11 */// 13
)).Count()/* 16 *//* 17 *///18
; //24
}
......@@ -4167,8 +4167,8 @@ void M(IEnumerable<int> nums)
{
foreach (var (a /* 12 */ , b /*16*/ ) in
/* 1 */from/* 2 */int /* 3 */ n1 /* 4 */in/* 5 */nums/* 6 */// 7
/* 8*/// 9
/* 10 *//* 11 */
/* 8*/// 9
/* 10 *//* 11 */
let a /* 12 */ = /* 13 */ n1 + n1/* 14*//* 15 */
let b /*16*/ = /*17*/ n1 * n1/*18*///19
select (a /* 12 */ , b /*16*/ )/*22*//*23*/)
......@@ -4215,13 +4215,13 @@ class C
void M(IEnumerable<int> nums)
{
foreach (var n1 /* 4 */in
/* 17 */// 18
/* 1 */from/* 2 */int /* 3 */ n1 /* 4 */in/* 5 */nums/* 6 */// 7
/* 8*/// 9
/* 10 */
where/* 11 *//* 12 */n1 /* 13 */ > /* 14 */ 0/* 15 */// 16
/* 17 */// 18
/* 1 */from/* 2 */int /* 3 */ n1 /* 4 */in/* 5 */nums/* 6 */// 7
/* 8*/// 9
/* 10 */
where/* 11 *//* 12 */n1 /* 13 */ > /* 14 */ 0/* 15 */// 16
select n1/* 4 *//* 21 */// 22
/*23*//*24*/
/*23*//*24*/
)
{
/*19*/
......@@ -4245,9 +4245,9 @@ void M(IEnumerable<int> nums)
n1 =>
/* 12 */n1 /* 13 */ > /* 14 */ 0/* 15 */// 16
).Select(
/* 1 *//* 2 *//* 17 */// 18
/* 3 */n1 /* 4 */=> n1/* 4 *//* 21 */// 22
/*23*//*24*//* 5 */// 7
/* 1 *//* 2 *//* 17 */// 18
/* 3 */n1 /* 4 */=> n1/* 4 *//* 21 */// 22
/*23*//*24*//* 5 */// 7
))
{
/*19*/
......
......@@ -148,15 +148,16 @@ void Method()
{{
// Start comment previous line
#pragma warning disable CS0219 // {CSharpResources.WRN_UnreferencedVarAssg_Title}
/* Start comment same line */
/* Start comment same line */
int x = 0; // End comment same line
#pragma warning restore CS0219 // {CSharpResources.WRN_UnreferencedVarAssg_Title}
/* End comment next line */
/* End comment next line */
}}
}}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsSuppression)]
[WorkItem(16681, "https://github.com/dotnet/roslyn/issues/16681")]
public async Task TestPragmaWarningDirectiveWithDocumentationComment()
{
await TestAsync(
......@@ -172,7 +173,7 @@ sealed class Class
sealed class Class
{{
#pragma warning disable CS0628 // {CSharpResources.WRN_ProtectedInSealed_Title}
/// <summary>Text</summary>
/// <summary>Text</summary>
protected void Method()
#pragma warning restore CS0628 // {CSharpResources.WRN_ProtectedInSealed_Title}
{{
......
......@@ -697,15 +697,15 @@ void Goo()
{
if (b) /*8*/
{ /*9*/
/*10*/
/*10*/
goo(); /*11*/
/*12*/
/*12*/
} /*13*/
else /*14*/
{ /*15*/
/*16*/
/*16*/
goo(); /*17*/
/*18*/
/*18*/
} /*19*/
}
else
......
......@@ -501,7 +501,7 @@ void M()
{
void M()
{/*C0*/
/*C1*/
/*C1*/
_ = M2()/*C2*/;/*C3*/
/*C4*/
}
......@@ -556,9 +556,9 @@ void M()
{
void M()
{/*C0*/
/*C1*/
/*C1*/
var unused = M2()/*C2*/;/*C3*/
/*C4*/
/*C4*/
}
int M2() => 0;
......
......@@ -126,8 +126,11 @@ protected override LineColumnRule GetLineColumnRuleBetween(SyntaxTrivia trivia1,
// comments case
if (trivia2.IsRegularOrDocComment())
{
// start of new comments group
if (!trivia1.IsRegularComment() || existingWhitespaceBetween.Lines > 1)
// Start of new comments group.
//
// 1. Comment groups must contain the same kind of comments
// 2. Every block comment is a group of its own
if (!trivia1.IsKind(trivia2.Kind()) || trivia2.IsMultiLineComment() || trivia2.IsMultiLineDocComment() || existingWhitespaceBetween.Lines > 1)
{
if (this.FormattingRules.GetAdjustNewLinesOperation(this.Token1, this.Token2) != null)
{
......
......@@ -6549,7 +6549,44 @@ void Method()
[Fact]
[WorkItem(772311, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/772311")]
[Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task CommentAtTheEndOfLine()
public async Task LineCommentAtTheEndOfLine()
{
var code = @"
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(); // this is a comment
// that I would like to keep
// properly indented
}
}
";
var expected = @"
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(); // this is a comment
// that I would like to keep
// properly indented
}
}
";
await AssertFormatAsync(expected, code);
}
[Fact]
[WorkItem(38224, "https://github.com/dotnet/roslyn/issues/38224")]
[Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task BlockCommentAtTheEndOfLine1()
{
var code = @"
using System;
......@@ -6574,7 +6611,44 @@ class Program
static void Main(string[] args)
{
Console.WriteLine(); /* this is a comment */
// that I would like to keep
// that I would like to keep
// properly indented
}
}
";
await AssertFormatAsync(expected, code);
}
[Fact]
[WorkItem(38224, "https://github.com/dotnet/roslyn/issues/38224")]
[Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task BlockCommentAtTheEndOfLine2()
{
var code = @"
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(); // this is a comment
/* that I would like to keep */
// properly indented
}
}
";
var expected = @"
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(); // this is a comment
/* that I would like to keep */
// properly indented
}
......@@ -6583,6 +6657,26 @@ static void Main(string[] args)
await AssertFormatAsync(expected, code);
}
[Fact]
[WorkItem(38224, "https://github.com/dotnet/roslyn/issues/38224")]
[Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task BlockCommentAtBeginningOfLine()
{
var code = @"
using System;
class Program
{
static void Main(
int x, // Some comment
/*A*/ int y)
{
}
}
";
await AssertFormatAsync(code, code);
}
[Fact]
[WorkItem(772311, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/772311")]
[Trait(Traits.Feature, Traits.Features.Formatting)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册