protected override void CollectBlockSpans(
            CompilationUnitSyntax compilationUnit,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(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.CreateBlockSpan(
                          externsAndUsings, autoCollapse: true,
                          type: BlockTypes.Nonstructural, isCollapsible: true));

            if (compilationUnit.Usings.Count > 0 ||
                compilationUnit.Externs.Count > 0 ||
                compilationUnit.Members.Count > 0 ||
                compilationUnit.AttributeLists.Count > 0)
            {
                CSharpStructureHelpers.CollectCommentBlockSpans(compilationUnit.EndOfFileToken.LeadingTrivia, spans);
            }
        }
        protected override void CollectBlockSpans(
            OperatorDeclarationSyntax operatorDeclaration,
            ArrayBuilder <BlockSpan> spans,
            bool isMetadataAsSource,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, spans, isMetadataAsSource);

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

            SyntaxNodeOrToken current = operatorDeclaration;
            var nextSibling           = current.GetNextSibling();

            // Check IsNode to compress blank lines after this node if it is the last child of the parent.
            var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.OperatorDeclaration);

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   operatorDeclaration,
                                   operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                                   compressEmptyLines: compressEmptyLines,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
Пример #3
0
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            IndexerDeclarationSyntax indexerDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptions options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(indexerDeclaration, ref spans, options);

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

            SyntaxNodeOrToken current = indexerDeclaration;
            var nextSibling           = current.GetNextSibling();

            // Check IsNode to compress blank lines after this node if it is the last child of the parent.
            //
            // Indexers are grouped together with properties in Metadata as Source.
            var compressEmptyLines = options.IsMetadataAsSource &&
                                     (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.IndexerDeclaration) || nextSibling.IsKind(SyntaxKind.PropertyDeclaration));

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   indexerDeclaration,
                                   indexerDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                                   compressEmptyLines: compressEmptyLines,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            AccessorDeclarationSyntax accessorDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptions options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(accessorDeclaration, ref spans, options);

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

            SyntaxNodeOrToken current = accessorDeclaration;
            var nextSibling           = current.GetNextSibling();

            // Check IsNode to compress blank lines after this node if it is the last child of the parent.
            //
            // All accessor kinds are grouped together in Metadata as Source.
            var compressEmptyLines = options.IsMetadataAsSource &&
                                     (!nextSibling.IsNode || nextSibling.AsNode() is AccessorDeclarationSyntax);

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   accessorDeclaration,
                                   accessorDeclaration.Keyword,
                                   compressEmptyLines: compressEmptyLines,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            TypeDeclarationSyntax typeDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(typeDeclaration, spans);

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

                var type = typeDeclaration.Kind() == SyntaxKind.InterfaceDeclaration
                    ? BlockTypes.Interface
                    : typeDeclaration.Kind() == SyntaxKind.StructDeclaration
                        ? BlockTypes.Structure
                        : BlockTypes.Class;
                spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                              typeDeclaration,
                              lastToken,
                              autoCollapse: false,
                              type: type,
                              isCollapsible: true));
            }

            // add any leading comments before the end of the type block
            if (!typeDeclaration.CloseBraceToken.IsMissing)
            {
                var leadingTrivia = typeDeclaration.CloseBraceToken.LeadingTrivia;
                CSharpStructureHelpers.CollectCommentBlockSpans(leadingTrivia, spans);
            }
        }
        protected override void CollectBlockSpans(
            EnumDeclarationSyntax enumDeclaration,
            ArrayBuilder <BlockSpan> spans,
            bool isMetadataAsSource,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(enumDeclaration, spans, isMetadataAsSource);

            if (!enumDeclaration.OpenBraceToken.IsMissing &&
                !enumDeclaration.CloseBraceToken.IsMissing)
            {
                SyntaxNodeOrToken current = enumDeclaration;
                var nextSibling           = current.GetNextSibling();

                // Check IsNode to compress blank lines after this node if it is the last child of the parent.
                var compressEmptyLines = !nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax;

                spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                       enumDeclaration,
                                       enumDeclaration.Identifier,
                                       compressEmptyLines: compressEmptyLines,
                                       autoCollapse: false,
                                       type: BlockTypes.Member,
                                       isCollapsible: true));
            }

            // add any leading comments before the end of the type block
            if (!enumDeclaration.CloseBraceToken.IsMissing)
            {
                var leadingTrivia = enumDeclaration.CloseBraceToken.LeadingTrivia;
                CSharpStructureHelpers.CollectCommentBlockSpans(leadingTrivia, spans);
            }
        }
Пример #7
0
        protected override void CollectBlockSpans(
            SimpleLambdaExpressionSyntax 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.CreateBlockSpan(
                          lambdaExpression,
                          lambdaExpression.ArrowToken,
                          lastToken,
                          autoCollapse: false,
                          type: BlockTypes.AnonymousMethod,
                          isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            CompilationUnitSyntax compilationUnit,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptions options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(compilationUnit, ref spans, options);

            // 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.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   externsAndUsings, compressEmptyLines: false, autoCollapse: true,
                                   type: BlockTypes.Imports, isCollapsible: true));

            if (compilationUnit.Usings.Count > 0 ||
                compilationUnit.Externs.Count > 0 ||
                compilationUnit.Members.Count > 0 ||
                compilationUnit.AttributeLists.Count > 0)
            {
                CSharpStructureHelpers.CollectCommentBlockSpans(compilationUnit.EndOfFileToken.LeadingTrivia, ref spans);
            }
        }
        protected override void CollectBlockSpans(
            EnumDeclarationSyntax enumDeclaration,
            ArrayBuilder <BlockSpan> spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(enumDeclaration, spans);

            if (!enumDeclaration.OpenBraceToken.IsMissing &&
                !enumDeclaration.CloseBraceToken.IsMissing)
            {
                spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                              enumDeclaration,
                              enumDeclaration.Identifier,
                              autoCollapse: false,
                              type: BlockTypes.Enum,
                              isCollapsible: true));
            }

            // add any leading comments before the end of the type block
            if (!enumDeclaration.CloseBraceToken.IsMissing)
            {
                var leadingTrivia = enumDeclaration.CloseBraceToken.LeadingTrivia;
                CSharpStructureHelpers.CollectCommentBlockSpans(leadingTrivia, spans);
            }
        }
Пример #10
0
        protected override void CollectBlockSpans(
            PropertyDeclarationSyntax propertyDeclaration,
            ArrayBuilder <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(propertyDeclaration, spans, optionProvider);

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

            SyntaxNodeOrToken current = propertyDeclaration;
            var nextSibling           = current.GetNextSibling();

            // Check IsNode to compress blank lines after this node if it is the last child of the parent.
            //
            // Properties are grouped together with indexers in Metadata as Source.
            var compressEmptyLines = optionProvider.IsMetadataAsSource &&
                                     (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.PropertyDeclaration) || nextSibling.IsKind(SyntaxKind.IndexerDeclaration));

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   propertyDeclaration,
                                   propertyDeclaration.Identifier,
                                   compressEmptyLines: compressEmptyLines,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            EventDeclarationSyntax eventDeclaration,
            ArrayBuilder <BlockSpan> spans,
            bool isMetadataAsSource,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(eventDeclaration, spans, isMetadataAsSource);

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

            SyntaxNodeOrToken current = eventDeclaration;
            var nextSibling           = current.GetNextSibling();

            // Check IsNode to compress blank lines after this node if it is the last child of the parent.
            //
            // Full events are grouped together with event field definitions in Metadata as Source.
            var compressEmptyLines = isMetadataAsSource &&
                                     (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.EventDeclaration) || nextSibling.IsKind(SyntaxKind.EventFieldDeclaration));

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   eventDeclaration,
                                   eventDeclaration.Identifier,
                                   compressEmptyLines: compressEmptyLines,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
Пример #12
0
        protected override void CollectBlockSpans(
            DestructorDeclarationSyntax destructorDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            CancellationToken cancellationToken
            )
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(
                destructorDeclaration,
                ref spans,
                optionProvider
                );

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

            spans.AddIfNotNull(
                CSharpStructureHelpers.CreateBlockSpan(
                    destructorDeclaration,
                    destructorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                    compressEmptyLines: false,
                    autoCollapse: true,
                    type: BlockTypes.Member,
                    isCollapsible: true
                    )
                );
        }
Пример #13
0
        protected override void CollectBlockSpans(
            ConversionOperatorDeclarationSyntax operatorDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, ref spans, optionProvider);

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

            SyntaxNodeOrToken current = operatorDeclaration;
            var nextSibling           = current.GetNextSibling();

            // Check IsNode to compress blank lines after this node if it is the last child of the parent.
            //
            // Whitespace between conversion operators is collapsed in Metadata as Source.
            var compressEmptyLines = optionProvider.IsMetadataAsSource &&
                                     (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConversionOperatorDeclaration));

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   operatorDeclaration,
                                   operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                                   compressEmptyLines: compressEmptyLines,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
Пример #14
0
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            AnonymousMethodExpressionSyntax anonymousMethod,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            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.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   anonymousMethod,
                                   startToken,
                                   lastToken,
                                   compressEmptyLines: false,
                                   autoCollapse: false,
                                   type: BlockTypes.Expression,
                                   isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            SimpleLambdaExpressionSyntax lambdaExpression,
            ArrayBuilder <BlockSpan> spans,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            // fault tolerance
            if (lambdaExpression.Body.IsMissing)
            {
                return;
            }

            if (!(lambdaExpression.Body is BlockSyntax lambdaBlock) ||
                lambdaBlock.OpenBraceToken.IsMissing ||
                lambdaBlock.CloseBraceToken.IsMissing)
            {
                return;
            }

            var lastToken = CSharpStructureHelpers.GetLastInlineMethodBlockToken(lambdaExpression);

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

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   lambdaExpression,
                                   lambdaExpression.ArrowToken,
                                   lastToken,
                                   autoCollapse: false,
                                   type: BlockTypes.Expression,
                                   isCollapsible: true));
        }
Пример #16
0
        protected override void CollectBlockSpans(
            ParenthesizedLambdaExpressionSyntax lambdaExpression,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            CancellationToken cancellationToken)
        {
            // fault tolerance
            if (lambdaExpression.Body.IsMissing)
            {
                return;
            }

            if (!(lambdaExpression.Body is BlockSyntax lambdaBlock) ||
                lambdaBlock.OpenBraceToken.IsMissing ||
                lambdaBlock.CloseBraceToken.IsMissing)
            {
                return;
            }

            var lastToken = CSharpStructureHelpers.GetLastInlineMethodBlockToken(lambdaExpression);

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

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   lambdaExpression,
                                   lambdaExpression.ArrowToken,
                                   lastToken,
                                   compressEmptyLines: false,
                                   autoCollapse: false,
                                   type: BlockTypes.Expression,
                                   isCollapsible: true));
        }
Пример #17
0
        protected override void CollectBlockSpans(
            AnonymousMethodExpressionSyntax anonymousMethod,
            ArrayBuilder <BlockSpan> 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.CreateBlockSpan(
                          anonymousMethod,
                          startToken,
                          lastToken,
                          autoCollapse: false,
                          type: BlockTypes.AnonymousMethod,
                          isCollapsible: true));
        }
Пример #18
0
        protected override void CollectBlockSpans(
            TypeDeclarationSyntax typeDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            CancellationToken cancellationToken
            )
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(
                typeDeclaration,
                ref spans,
                optionProvider
                );

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

                SyntaxNodeOrToken current = typeDeclaration;
                var nextSibling           = current.GetNextSibling();

                // Check IsNode to compress blank lines after this node if it is the last child of the parent.
                //
                // Collapse to Definitions doesn't collapse type nodes, but a Toggle All Outlining would collapse groups
                // of types to the compressed form of not showing blank lines. All kinds of types are grouped together
                // in Metadata as Source.
                var compressEmptyLines =
                    optionProvider.IsMetadataAsSource &&
                    (!nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax);

                spans.AddIfNotNull(
                    CSharpStructureHelpers.CreateBlockSpan(
                        typeDeclaration,
                        lastToken,
                        compressEmptyLines: compressEmptyLines,
                        autoCollapse: false,
                        type: BlockTypes.Type,
                        isCollapsible: true
                        )
                    );
            }

            // add any leading comments before the end of the type block
            if (!typeDeclaration.CloseBraceToken.IsMissing)
            {
                var leadingTrivia = typeDeclaration.CloseBraceToken.LeadingTrivia;
                CSharpStructureHelpers.CollectCommentBlockSpans(leadingTrivia, ref spans);
            }
        }
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            NamespaceDeclarationSyntax namespaceDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptions options,
            CancellationToken cancellationToken)
        {
            // add leading comments
            CSharpStructureHelpers.CollectCommentBlockSpans(namespaceDeclaration, ref spans, options);

            if (!namespaceDeclaration.OpenBraceToken.IsMissing &&
                !namespaceDeclaration.CloseBraceToken.IsMissing)
            {
                spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                       namespaceDeclaration,
                                       namespaceDeclaration.Name.GetLastToken(includeZeroWidth: true),
                                       compressEmptyLines: false,
                                       autoCollapse: false,
                                       type: BlockTypes.Namespace,
                                       isCollapsible: true));
            }

            // 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.CollectCommentBlockSpans(externsAndUsings.First(), ref spans, options);
            }

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   externsAndUsings, compressEmptyLines: false, autoCollapse: true,
                                   type: BlockTypes.Imports, isCollapsible: true));

            // finally, add any leading comments before the end of the namespace block
            if (!namespaceDeclaration.CloseBraceToken.IsMissing)
            {
                CSharpStructureHelpers.CollectCommentBlockSpans(
                    namespaceDeclaration.CloseBraceToken.LeadingTrivia, ref spans);
            }
        }
        protected override void CollectBlockSpans(
            NamespaceDeclarationSyntax namespaceDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            // add leading comments
            CSharpStructureHelpers.CollectCommentBlockSpans(namespaceDeclaration, spans);

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

            // 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.CollectCommentBlockSpans(externsAndUsings.First(), spans);
            }

            spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                          externsAndUsings, autoCollapse: true,
                          type: BlockTypes.Nonstructural, isCollapsible: true));

            // finally, add any leading comments before the end of the namespace block
            if (!namespaceDeclaration.CloseBraceToken.IsMissing)
            {
                CSharpStructureHelpers.CollectCommentBlockSpans(namespaceDeclaration.CloseBraceToken.LeadingTrivia, spans);
            }
        }
        protected override void CollectBlockSpans(
            EventDeclarationSyntax eventDeclaration,
            ArrayBuilder <BlockSpan> spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(eventDeclaration, spans);

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

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   eventDeclaration,
                                   eventDeclaration.Identifier,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
Пример #22
0
        protected override void CollectBlockSpans(
            AccessorDeclarationSyntax accessorDeclaration,
            ArrayBuilder <BlockSpan> spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(accessorDeclaration, spans);

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

            spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                          accessorDeclaration,
                          accessorDeclaration.Keyword,
                          autoCollapse: true,
                          type: BlockTypes.Accessor,
                          isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            PropertyDeclarationSyntax propertyDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(propertyDeclaration, spans);

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

            spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                          propertyDeclaration,
                          propertyDeclaration.Identifier,
                          autoCollapse: true,
                          type: BlockTypes.Property,
                          isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            ConstructorDeclarationSyntax constructorDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(constructorDeclaration, spans);

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

            spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                          constructorDeclaration,
                          constructorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                          autoCollapse: true,
                          type: BlockTypes.Constructor,
                          isCollapsible: true));
        }
Пример #25
0
        protected override void CollectBlockSpans(
            MethodDeclarationSyntax methodDeclaration,
            ArrayBuilder <BlockSpan> spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(methodDeclaration, spans);

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

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   methodDeclaration,
                                   methodDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            IndexerDeclarationSyntax indexerDeclaration,
            ArrayBuilder <BlockSpan> spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(indexerDeclaration, spans);

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

            spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                          indexerDeclaration,
                          indexerDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                          autoCollapse: true,
                          type: BlockTypes.Indexer,
                          isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            FileScopedNamespaceDeclarationSyntax fileScopedNamespaceDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptions options,
            CancellationToken cancellationToken)
        {
            // add leading comments
            CSharpStructureHelpers.CollectCommentBlockSpans(fileScopedNamespaceDeclaration, ref spans, options);

            // extern aliases and usings are outlined in a single region
            var externsAndUsings = Enumerable.Union <SyntaxNode>(fileScopedNamespaceDeclaration.Externs, fileScopedNamespaceDeclaration.Usings).ToImmutableArray();

            // add any leading comments before the extern aliases and usings
            if (externsAndUsings.Any())
            {
                CSharpStructureHelpers.CollectCommentBlockSpans(externsAndUsings.First(), ref spans, options);
            }

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   externsAndUsings, compressEmptyLines: false, autoCollapse: true,
                                   type: BlockTypes.Imports, isCollapsible: true, isDefaultCollapsed: options.CollapseImportsWhenFirstOpened));
        }
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            EnumDeclarationSyntax enumDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptions options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(enumDeclaration, ref spans, options);

            if (!enumDeclaration.OpenBraceToken.IsMissing &&
                !enumDeclaration.CloseBraceToken.IsMissing)
            {
                SyntaxNodeOrToken current = enumDeclaration;
                var nextSibling           = current.GetNextSibling();

                // Check IsNode to compress blank lines after this node if it is the last child of the parent.
                //
                // Whitespace between type declarations is collapsed in Metadata as Source.
                var compressEmptyLines = options.IsMetadataAsSource &&
                                         (!nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax);

                spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                       enumDeclaration,
                                       enumDeclaration.Identifier,
                                       compressEmptyLines: compressEmptyLines,
                                       autoCollapse: false,
                                       type: BlockTypes.Member,
                                       isCollapsible: true));
            }

            // add any leading comments before the end of the type block
            if (!enumDeclaration.CloseBraceToken.IsMissing)
            {
                var leadingTrivia = enumDeclaration.CloseBraceToken.LeadingTrivia;
                CSharpStructureHelpers.CollectCommentBlockSpans(leadingTrivia, ref spans);
            }
        }