diff --git a/src/EditorFeatures/CSharp/Outlining/CSharpOutliningHelpers.cs b/src/EditorFeatures/CSharp/Outlining/CSharpOutliningHelpers.cs index 13abd5a4513d6bce5a89405c30a3ab9296e049d4..3c24622cf4ce018d59d2bce37a6c4ec6d972feeb 100644 --- a/src/EditorFeatures/CSharp/Outlining/CSharpOutliningHelpers.cs +++ b/src/EditorFeatures/CSharp/Outlining/CSharpOutliningHelpers.cs @@ -16,6 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.Outlining internal static class CSharpOutliningHelpers { public const string Ellipsis = "..."; + public const string MultiLineCommentSuffix = "*/"; public const int MaxXmlDocCommentBannerLength = 120; private static int GetCollapsibleStart(SyntaxToken firstToken) @@ -121,8 +122,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment) } else { - int suffixLength = "*/".Length; - text = text.Substring(0, text.Length - suffixLength); + text = text.EndsWith(MultiLineCommentSuffix) ? text.Substring(0, text.Length - MultiLineCommentSuffix.Length) : text; } return CreateCommentBannerTextWithPrefix(text, "/*"); diff --git a/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs b/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs index b2a038234b6b4fa05684c0f0fc25c01f826f06a8..86c070fc0563995139e1a8cafb30d141fb91e8f3 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs @@ -163,5 +163,45 @@ public void TestMultilineCommentOnOneLine() 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); + } } }