Пример #1
0
        protected override void CollectBlockSpans(
            MethodDeclarationSyntax methodDeclaration,
            ArrayBuilder <BlockSpan> spans,
            OptionSet options,
            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));
        }
Пример #2
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,
            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));
        }
        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);
            }
        }
Пример #6
0
        protected override void CollectBlockSpans(
            SimpleLambdaExpressionSyntax lambdaExpression,
            ArrayBuilder <BlockSpan> spans,
            bool isMetadataAsSource,
            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,
                                   compressEmptyLines: false,
                                   autoCollapse: false,
                                   type: BlockTypes.Expression,
                                   isCollapsible: true));
        }
Пример #7
0
        protected override void CollectBlockSpans(
            ParenthesizedLambdaExpressionSyntax lambdaExpression,
            ArrayBuilder <BlockSpan> spans,
            OptionSet options,
            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.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
                                   lambdaExpression,
                                   lambdaExpression.ArrowToken,
                                   lastToken,
                                   autoCollapse: false,
                                   type: BlockTypes.Expression,
                                   isCollapsible: true));
        }
Пример #8
0
        protected override void CollectBlockSpans(
            SyntaxToken previousToken,
            SimpleLambdaExpressionSyntax lambdaExpression,
            ref TemporaryArray <BlockSpan> spans,
            BlockStructureOptions options,
            CancellationToken cancellationToken)
        {
            // fault tolerance
            if (lambdaExpression.Body.IsMissing)
            {
                return;
            }

            if (lambdaExpression.Body is not 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));
        }
Пример #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));
        }
Пример #10
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);
            }
        }
Пример #11
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);
            }
        }
        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
                    );
            }
        }