提交 c29dc68a 编写于 作者: B Balaji

Merge pull request #816 from basoundr/fix791ArgExcpMultiComment

Make OutliningSpan Creation not assume MultiLine Comment always end with...
...@@ -16,6 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.Outlining ...@@ -16,6 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.Outlining
internal static class CSharpOutliningHelpers internal static class CSharpOutliningHelpers
{ {
public const string Ellipsis = "..."; public const string Ellipsis = "...";
public const string MultiLineCommentSuffix = "*/";
public const int MaxXmlDocCommentBannerLength = 120; public const int MaxXmlDocCommentBannerLength = 120;
private static int GetCollapsibleStart(SyntaxToken firstToken) private static int GetCollapsibleStart(SyntaxToken firstToken)
...@@ -121,8 +122,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment) ...@@ -121,8 +122,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
} }
else else
{ {
int suffixLength = "*/".Length; text = text.EndsWith(MultiLineCommentSuffix) ? text.Substring(0, text.Length - MultiLineCommentSuffix.Length) : text;
text = text.Substring(0, text.Length - suffixLength);
} }
return CreateCommentBannerTextWithPrefix(text, "/*"); return CreateCommentBannerTextWithPrefix(text, "/*");
......
...@@ -163,5 +163,45 @@ public void TestMultilineCommentOnOneLine() ...@@ -163,5 +163,45 @@ public void TestMultilineCommentOnOneLine()
AssertRegion(expectedRegion, actualRegion); AssertRegion(expectedRegion, actualRegion);
} }
[WorkItem(791)]
[WorkItem(1108049)]
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
public void TestIncompleteMultilineCommentZeroSpace()
{
var tree = ParseLines("/*");
var multiLineCommentTrivia = tree.GetRoot().FindToken(0).LeadingTrivia;
var regions = CSharpOutliningHelpers.CreateCommentRegions(multiLineCommentTrivia).ToList();
Assert.Equal(1, regions.Count);
var actualRegion = regions[0];
var expectedRegion = new OutliningSpan(
TextSpan.FromBounds(0, 2),
"/* ...",
autoCollapse: true);
AssertRegion(expectedRegion, actualRegion);
}
[WorkItem(791)]
[WorkItem(1108049)]
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
public void TestIncompleteMultilineCommentSingleSpace()
{
var tree = ParseLines("/* ");
var multiLineCommentTrivia = tree.GetRoot().FindToken(0).LeadingTrivia;
var regions = CSharpOutliningHelpers.CreateCommentRegions(multiLineCommentTrivia).ToList();
Assert.Equal(1, regions.Count);
var actualRegion = regions[0];
var expectedRegion = new OutliningSpan(
TextSpan.FromBounds(0, 3),
"/* ...",
autoCollapse: true);
AssertRegion(expectedRegion, actualRegion);
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册