private async Task <IList <TodoComment> > GetTodoCommentsInCurrentProcessAsync(
            Document document, IList <TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // strongly hold onto text and tree
            var syntaxDoc = await SyntacticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);

            // reuse list
            var todoList = new List <TodoComment>();

            foreach (var trivia in syntaxDoc.Root.DescendantTrivia())
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (!ContainsComments(trivia))
                {
                    continue;
                }

                AppendTodoComments(commentDescriptors, syntaxDoc, trivia, todoList);
            }

            return(todoList);
        }
Esempio n. 2
0
        private Indenter GetIndenter(
            Document document,
            int lineNumber,
            FormattingOptions.IndentStyle indentStyle,
            CancellationToken cancellationToken
            )
        {
            var documentOptions = document
                                  .GetOptionsAsync(cancellationToken)
                                  .WaitAndGetResult_CanCallOnBackground(cancellationToken);
            var syntacticDoc = SyntacticDocument
                               .CreateAsync(document, cancellationToken)
                               .WaitAndGetResult_CanCallOnBackground(cancellationToken);

            var sourceText       = syntacticDoc.Root.SyntaxTree.GetText(cancellationToken);
            var lineToBeIndented = sourceText.Lines[lineNumber];

            var formattingRules = GetFormattingRules(document, lineToBeIndented.Start, indentStyle);

            return(new Indenter(
                       this,
                       syntacticDoc,
                       formattingRules,
                       documentOptions,
                       lineToBeIndented,
                       cancellationToken
                       ));
        }
Esempio n. 3
0
        public static async Task <Location> ConvertLocationAsync(
            this DiagnosticDataLocation dataLocation, Project project, CancellationToken cancellationToken)
        {
            if (dataLocation?.DocumentId == null)
            {
                return(Location.None);
            }

            var document = project.GetDocument(dataLocation?.DocumentId);

            if (document == null)
            {
                return(Location.None);
            }


            if (document.SupportsSyntaxTree)
            {
                var syntacticDocument = await SyntacticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);

                return(dataLocation.ConvertLocation(syntacticDocument));
            }

            return(dataLocation.ConvertLocation());
        }
Esempio n. 4
0
        public async Task <ImmutableArray <TodoComment> > GetTodoCommentsAsync(
            Document document,
            ImmutableArray <TodoCommentDescriptor> commentDescriptors,
            CancellationToken cancellationToken)
        {
            if (commentDescriptors.IsEmpty)
            {
                return(ImmutableArray <TodoComment> .Empty);
            }

            cancellationToken.ThrowIfCancellationRequested();

            // strongly hold onto text and tree
            var syntaxDoc = await SyntacticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);

            // reuse list
            using var _ = ArrayBuilder <TodoComment> .GetInstance(out var todoList);

            foreach (var trivia in syntaxDoc.Root.DescendantTrivia())
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (!ContainsComments(trivia))
                {
                    continue;
                }

                AppendTodoComments(commentDescriptors, syntaxDoc, trivia, todoList);
            }

            return(todoList.ToImmutable());
        }
Esempio n. 5
0
        protected override async Task <AbstractIndenter> GetIndenterAsync(
            Document document, TextLine lineToBeIndented, IEnumerable <IFormattingRule> formattingRules, OptionSet optionSet, CancellationToken cancellationToken)
        {
            var syntacticDocument = await SyntacticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);

            return(new Indenter(syntacticDocument, formattingRules, optionSet, lineToBeIndented, cancellationToken));
        }
Esempio n. 6
0
        public static async ValueTask <Location> ConvertLocationAsync(
            this DiagnosticDataLocation?dataLocation, Project project, CancellationToken cancellationToken)
        {
            if (dataLocation?.DocumentId == null)
            {
                return(Location.None);
            }

            var textDocument = project.GetTextDocument(dataLocation.DocumentId)
                               ?? await project.GetSourceGeneratedDocumentAsync(dataLocation.DocumentId, cancellationToken).ConfigureAwait(false);

            if (textDocument == null)
            {
                return(Location.None);
            }

            if (textDocument is Document document && document.SupportsSyntaxTree)
            {
                var syntacticDocument = await SyntacticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);

                return(dataLocation.ConvertLocation(syntacticDocument));
            }

            return(dataLocation.ConvertLocation());
        }
            public AbstractIndenter(Document document, IEnumerable <IFormattingRule> rules, OptionSet optionSet, ITextSnapshotLine lineToBeIndented, CancellationToken cancellationToken)
            {
                this.OptionSet         = optionSet;
                this.Document          = SyntacticDocument.CreateAsync(document, cancellationToken).WaitAndGetResult(cancellationToken);
                this.LineToBeIndented  = lineToBeIndented;
                this.TabSize           = this.OptionSet.GetOption(FormattingOptions.TabSize, this.Document.Root.Language);
                this.CancellationToken = cancellationToken;

                this.Rules  = rules;
                this.Tree   = this.Document.SyntaxTree;
                this.Finder = new BottomUpBaseIndentationFinder(
                    new ChainedFormattingRules(this.Rules, OptionSet),
                    this.TabSize,
                    this.OptionSet.GetOption(FormattingOptions.IndentationSize, this.Document.Root.Language),
                    tokenStream: null);
            }
Esempio n. 8
0
        public async Task <IList <OutliningSpan> > GetOutliningSpansAsync(Document document, CancellationToken cancellationToken)
        {
            try
            {
                var syntaxDocument = await SyntacticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);

                // change this to shared pool once RI
                var regions = new List <OutliningSpan>();
                RegionCollector.CollectOutliningSpans(syntaxDocument, _nodeOutlinerMap, _triviaOutlinerMap, regions, cancellationToken);

                return(regions);
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }