Beispiel #1
0
        protected override void CollectBlockSpans(
            TypeDeclarationSyntax typeDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentRegions(typeDeclaration, spans);

            if (!typeDeclaration.OpenBraceToken.IsMissing &&
                !typeDeclaration.CloseBraceToken.IsMissing)
            {
                var lastToken = typeDeclaration.TypeParameterList == null
                    ? typeDeclaration.Identifier
                    : typeDeclaration.TypeParameterList.GetLastToken(includeZeroWidth: true);

                spans.Add(CSharpStructureHelpers.CreateRegion(
                              typeDeclaration,
                              lastToken,
                              autoCollapse: false));
            }

            // add any leading comments before the end of the type block
            if (!typeDeclaration.CloseBraceToken.IsMissing)
            {
                var leadingTrivia = typeDeclaration.CloseBraceToken.LeadingTrivia;
                CSharpStructureHelpers.CollectCommentRegions(leadingTrivia, spans);
            }
        }
        protected override void CollectBlockSpans(
            ParenthesizedLambdaExpressionSyntax lambdaExpression,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            // fault tolerance
            if (lambdaExpression.Body.IsMissing)
            {
                return;
            }

            var lambdaBlock = lambdaExpression.Body as BlockSyntax;

            if (lambdaBlock == null ||
                lambdaBlock.OpenBraceToken.IsMissing ||
                lambdaBlock.CloseBraceToken.IsMissing)
            {
                return;
            }

            var lastToken = CSharpStructureHelpers.GetLastInlineMethodBlockToken(lambdaExpression);

            if (lastToken.Kind() == SyntaxKind.None)
            {
                return;
            }

            spans.Add(CSharpStructureHelpers.CreateRegion(
                          lambdaExpression,
                          lambdaExpression.ArrowToken,
                          lastToken,
                          autoCollapse: false));
        }
        protected override void CollectBlockSpans(
            AnonymousMethodExpressionSyntax anonymousMethod,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            // fault tolerance
            if (anonymousMethod.Block.IsMissing ||
                anonymousMethod.Block.OpenBraceToken.IsMissing ||
                anonymousMethod.Block.CloseBraceToken.IsMissing)
            {
                return;
            }

            var lastToken = CSharpStructureHelpers.GetLastInlineMethodBlockToken(anonymousMethod);

            if (lastToken.Kind() == SyntaxKind.None)
            {
                return;
            }

            var startToken = anonymousMethod.ParameterList != null
                ? anonymousMethod.ParameterList.GetLastToken(includeZeroWidth : true)
                : anonymousMethod.DelegateKeyword;

            spans.Add(CSharpStructureHelpers.CreateRegion(
                          anonymousMethod,
                          startToken,
                          lastToken,
                          autoCollapse: false));
        }
Beispiel #4
0
        protected override void CollectBlockSpans(
            EventDeclarationSyntax eventDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentRegions(eventDeclaration, spans);

            // fault tolerance
            if (eventDeclaration.AccessorList.IsMissing ||
                eventDeclaration.AccessorList.OpenBraceToken.IsMissing ||
                eventDeclaration.AccessorList.CloseBraceToken.IsMissing)
            {
                return;
            }

            spans.Add(CSharpStructureHelpers.CreateRegion(
                          eventDeclaration,
                          eventDeclaration.Identifier,
                          autoCollapse: true));
        }
        protected override void CollectBlockSpans(
            ConversionOperatorDeclarationSyntax operatorDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentRegions(operatorDeclaration, spans);

            // fault tolerance
            if (operatorDeclaration.Body == null ||
                operatorDeclaration.Body.OpenBraceToken.IsMissing ||
                operatorDeclaration.Body.CloseBraceToken.IsMissing)
            {
                return;
            }

            spans.Add(CSharpStructureHelpers.CreateRegion(
                          operatorDeclaration,
                          operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                          autoCollapse: true));
        }
        protected override void CollectBlockSpans(
            AccessorDeclarationSyntax accessorDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentRegions(accessorDeclaration, spans);

            // fault tolerance
            if (accessorDeclaration.Body == null ||
                accessorDeclaration.Body.OpenBraceToken.IsMissing ||
                accessorDeclaration.Body.CloseBraceToken.IsMissing)
            {
                return;
            }

            spans.Add(CSharpStructureHelpers.CreateRegion(
                          accessorDeclaration,
                          accessorDeclaration.Keyword,
                          autoCollapse: true));
        }
        protected override void CollectBlockSpans(
            EnumDeclarationSyntax enumDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentRegions(enumDeclaration, spans);

            if (!enumDeclaration.OpenBraceToken.IsMissing &&
                !enumDeclaration.CloseBraceToken.IsMissing)
            {
                spans.Add(CSharpStructureHelpers.CreateRegion(
                              enumDeclaration,
                              enumDeclaration.Identifier,
                              autoCollapse: false));
            }

            // add any leading comments before the end of the type block
            if (!enumDeclaration.CloseBraceToken.IsMissing)
            {
                var leadingTrivia = enumDeclaration.CloseBraceToken.LeadingTrivia;
                CSharpStructureHelpers.CollectCommentRegions(leadingTrivia, spans);
            }
        }
Beispiel #8
0
        protected override void CollectBlockSpans(
            CompilationUnitSyntax compilationUnit,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentRegions(compilationUnit, spans);

            // extern aliases and usings are outlined in a single region
            var externsAndUsings = new List <SyntaxNode>();

            externsAndUsings.AddRange(compilationUnit.Externs);
            externsAndUsings.AddRange(compilationUnit.Usings);
            externsAndUsings.Sort((node1, node2) => node1.SpanStart.CompareTo(node2.SpanStart));

            spans.Add(CSharpStructureHelpers.CreateRegion(externsAndUsings, autoCollapse: true));

            if (compilationUnit.Usings.Count > 0 ||
                compilationUnit.Externs.Count > 0 ||
                compilationUnit.Members.Count > 0 ||
                compilationUnit.AttributeLists.Count > 0)
            {
                CSharpStructureHelpers.CollectCommentRegions(compilationUnit.EndOfFileToken.LeadingTrivia, spans);
            }
        }
Beispiel #9
0
        protected override void CollectBlockSpans(
            NamespaceDeclarationSyntax namespaceDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            // add leading comments
            CSharpStructureHelpers.CollectCommentRegions(namespaceDeclaration, spans);

            if (!namespaceDeclaration.OpenBraceToken.IsMissing &&
                !namespaceDeclaration.CloseBraceToken.IsMissing)
            {
                spans.Add(CSharpStructureHelpers.CreateRegion(
                              namespaceDeclaration,
                              namespaceDeclaration.Name.GetLastToken(includeZeroWidth: true),
                              autoCollapse: false));
            }

            // extern aliases and usings are outlined in a single region
            var externsAndUsings = Enumerable.Union <SyntaxNode>(namespaceDeclaration.Externs, namespaceDeclaration.Usings)
                                   .OrderBy(node => node.SpanStart)
                                   .ToList();

            // add any leading comments before the extern aliases and usings
            if (externsAndUsings.Count > 0)
            {
                CSharpStructureHelpers.CollectCommentRegions(externsAndUsings.First(), spans);
            }

            spans.Add(CSharpStructureHelpers.CreateRegion(externsAndUsings, autoCollapse: true));

            // finally, add any leading comments before the end of the namespace block
            if (!namespaceDeclaration.CloseBraceToken.IsMissing)
            {
                CSharpStructureHelpers.CollectCommentRegions(namespaceDeclaration.CloseBraceToken.LeadingTrivia, spans);
            }
        }