Exemple #1
0
        private static BlockStructure CreateBlockStructure(Document document, BlockStructureContext context)
        {
            var options  = context.Document.Project.Solution.Workspace.Options;
            var language = context.Document.Project.Language;

            var showIndentGuidesForCodeLevelConstructs            = options.GetOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, language);
            var showIndentGuidesForDeclarationLevelConstructs     = options.GetOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, language);
            var showIndentGuidesForCommentsAndPreprocessorRegions = options.GetOption(BlockStructureOptions.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, language);
            var showOutliningForCodeLevelConstructs            = options.GetOption(BlockStructureOptions.ShowOutliningForCodeLevelConstructs, language);
            var showOutliningForDeclarationLevelConstructs     = options.GetOption(BlockStructureOptions.ShowOutliningForDeclarationLevelConstructs, language);
            var showOutliningForCommentsAndPreprocessorRegions = options.GetOption(BlockStructureOptions.ShowOutliningForCommentsAndPreprocessorRegions, language);

            var updatedSpans = ArrayBuilder <BlockSpan> .GetInstance();

            foreach (var span in context.Spans)
            {
                var updatedSpan = UpdateBlockSpan(span,
                                                  showIndentGuidesForCodeLevelConstructs,
                                                  showIndentGuidesForDeclarationLevelConstructs,
                                                  showIndentGuidesForCommentsAndPreprocessorRegions,
                                                  showOutliningForCodeLevelConstructs,
                                                  showOutliningForDeclarationLevelConstructs,
                                                  showOutliningForCommentsAndPreprocessorRegions);
                updatedSpans.Add(updatedSpan);
            }

            return(new BlockStructure(updatedSpans.ToImmutableAndFree()));
        }
Exemple #2
0
        public override BlockStructure GetBlockStructure(
            Document document, CancellationToken cancellationToken)
        {
            var context = new BlockStructureContext(document, cancellationToken);

            foreach (var provider in _providers)
            {
                provider.ProvideBlockStructure(context);
            }

            return(CreateBlockStructure(document, context));
        }
Exemple #3
0
        public override async Task <BlockStructure> GetBlockStructureAsync(
            Document document, CancellationToken cancellationToken)
        {
            var context = new BlockStructureContext(document, cancellationToken);

            foreach (var provider in _providers)
            {
                await provider.ProvideBlockStructureAsync(context).ConfigureAwait(false);
            }

            return(CreateBlockStructure(document, context));
        }
        /// <summary>
        /// Keep in sync with <see cref="ProvideBlockStructure"/>
        /// </summary>
        public override async Task ProvideBlockStructureAsync(BlockStructureContext context)
        {
            try
            {
                var syntaxRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

                ProvideBlockStructureWorker(context, syntaxRoot);
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
        /// <summary>
        /// Keep in sync with <see cref="ProvideBlockStructureAsync"/>
        /// </summary>
        public override void ProvideBlockStructure(BlockStructureContext context)
        {
            try
            {
                var syntaxRoot = context.Document.GetSyntaxRootSynchronously(context.CancellationToken);

                ProvideBlockStructureWorker(context, syntaxRoot);
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
        private void ProvideBlockStructureWorker(
            BlockStructureContext context, SyntaxNode syntaxRoot)
        {
            var spans = ArrayBuilder <BlockSpan> .GetInstance();

            BlockSpanCollector.CollectBlockSpans(
                context.Document, syntaxRoot, _nodeProviderMap, _triviaProviderMap, spans, context.CancellationToken);

            foreach (var span in spans)
            {
                context.AddBlockSpan(span);
            }

            spans.Free();
        }
 public abstract Task ProvideBlockStructureAsync(BlockStructureContext context);
 public virtual void ProvideBlockStructure(BlockStructureContext context)
 {
     ProvideBlockStructureAsync(context).Wait(context.CancellationToken);
 }