Пример #1
0
        protected override void CollectBlockSpans(
            PropertyDeclarationSyntax propertyDeclaration,
            ArrayBuilder <BlockSpan> 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(
            DestructorDeclarationSyntax destructorDeclaration,
            ImmutableArray <BlockSpan> .Builder spans,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(destructorDeclaration, spans);

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

            spans.Add(CSharpStructureHelpers.CreateBlockSpan(
                          destructorDeclaration,
                          destructorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                          autoCollapse: true,
                          type: BlockTypes.Destructor,
                          isCollapsible: true));
        }
        protected override void CollectBlockSpans(
            AccessorDeclarationSyntax accessorDeclaration,
            ArrayBuilder <BlockSpan> spans,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(accessorDeclaration, spans);

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

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   accessorDeclaration,
                                   accessorDeclaration.Keyword,
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   isCollapsible: true));
        }
Пример #4
0
        protected override void CollectBlockSpans(
            OperatorDeclarationSyntax operatorDeclaration,
            ArrayBuilder <BlockSpan> spans,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, spans);

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

            spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   operatorDeclaration,
                                   operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
                                   autoCollapse: true,
                                   type: BlockTypes.Member,
                                   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));
        }
Пример #6
0
        protected override void CollectBlockSpans(
            EventDeclarationSyntax eventDeclaration,
            ArrayBuilder <BlockSpan> spans,
            OptionSet options,
            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));
        }
        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,
            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);
            }
        }
Пример #9
0
        protected override void CollectBlockSpans(
            DestructorDeclarationSyntax destructorDeclaration,
            ArrayBuilder <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            CancellationToken cancellationToken)
        {
            CSharpStructureHelpers.CollectCommentBlockSpans(destructorDeclaration, 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));
        }
        protected override void CollectBlockSpans(
            NamespaceDeclarationSyntax namespaceDeclaration,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptionProvider optionProvider,
            CancellationToken cancellationToken
            )
        {
            // add leading comments
            CSharpStructureHelpers.CollectCommentBlockSpans(
                namespaceDeclaration,
                ref spans,
                optionProvider
                );

            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,
                    optionProvider
                    );
            }

            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
                    );
            }
        }