Пример #1
0
        public void TestSingleLineCommentGroupFollowedByDocumentationComment()
        {
            var tree = ParseLines("// Hello",
                                  string.Empty,
                                  "// C#!",
                                  "/// <summary></summary>",
                                  "class C",
                                  "{",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia   = typeDecl.GetLeadingTrivia();

            Assert.Equal(6, trivia.Count);

            var regions = CSharpOutliningHelpers.CreateCommentRegions(trivia).ToList();

            Assert.Equal(1, regions.Count);

            var actualRegion   = regions[0];
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 18),
                "// Hello ...",
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Пример #2
0
        public void TestSimpleComment2()
        {
            var tree = ParseLines("// Hello",
                                  "//",
                                  "// C#!",
                                  "class C",
                                  "{",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia   = typeDecl.GetLeadingTrivia();

            Assert.Equal(6, trivia.Count);

            var regions = CSharpOutliningHelpers.CreateCommentRegions(trivia).ToList();

            Assert.Equal(1, regions.Count);

            var actualRegion   = regions[0];
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 20),
                "// Hello ...",
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Пример #3
0
        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);
        }
Пример #4
0
        internal override Task <OutliningSpan[]> GetRegionsAsync(Document document, int position)
        {
            var root   = document.GetSyntaxRootAsync(CancellationToken.None).Result;
            var trivia = root.FindTrivia(position, findInsideTrivia: true);

            var token = trivia.Token;

            if (token.LeadingTrivia.Contains(trivia))
            {
                return(Task.FromResult(CSharpOutliningHelpers.CreateCommentRegions(token.LeadingTrivia).ToArray()));
            }
            else if (token.TrailingTrivia.Contains(trivia))
            {
                return(Task.FromResult(CSharpOutliningHelpers.CreateCommentRegions(token.TrailingTrivia).ToArray()));
            }
            else
            {
                return(Task.FromResult(Contract.FailWithReturn <OutliningSpan[]>()));
            }
        }