Esempio n. 1
0
        internal static async Task <ImmutableArray <SyntaxToken> > GetIdentifierOrGlobalNamespaceTokensWithTextAsync(
            this Document document, SemanticModel model, string identifier, CancellationToken cancellationToken)
        {
            // It's very costly to walk an entire tree.  So if the tree is simple and doesn't contain
            // any unicode escapes in it, then we do simple string matching to find the tokens.
            var info = await SyntaxTreeIndex.GetIndexAsync(document, cancellationToken).ConfigureAwait(false);

            if (!info.ProbablyContainsIdentifier(identifier))
            {
                return(ImmutableArray <SyntaxToken> .Empty);
            }

            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            if (syntaxFacts == null)
            {
                return(ImmutableArray <SyntaxToken> .Empty);
            }

            var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var version = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);

            SourceText text = null;

            if (!info.ProbablyContainsEscapedIdentifier(identifier))
            {
                text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
            }

            return(FindReferenceCache.GetIdentifierOrGlobalNamespaceTokensWithText(syntaxFacts, document, version, model, root, text, identifier, cancellationToken));
        }
Esempio n. 2
0
        private async Task ProcessDocumentQueueAsync(
            Document document,
            HashSet <ISymbol> documentQueue,
            CancellationToken cancellationToken)
        {
            await _progress.OnFindInDocumentStartedAsync(document, cancellationToken).ConfigureAwait(false);

            SemanticModel?model = null;

            try
            {
                model = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

                // start cache for this semantic model
                FindReferenceCache.Start(model);

                foreach (var symbol in documentQueue)
                {
                    await ProcessDocumentAsync(document, model, symbol, cancellationToken).ConfigureAwait(false);
                }
            }
            finally
            {
                FindReferenceCache.Stop(model);

                await _progress.OnFindInDocumentCompletedAsync(document, cancellationToken).ConfigureAwait(false);
            }
        }
Esempio n. 3
0
        public static async Task <IEnumerable <SyntaxToken> > GetConstructorInitializerTokensAsync(this Document document, SemanticModel model, CancellationToken cancellationToken)
        {
            var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            if (syntaxFacts == null)
            {
                return(SpecializedCollections.EmptyEnumerable <SyntaxToken>());
            }

            return(FindReferenceCache.GetConstructorInitializerTokens(syntaxFacts, model, root, cancellationToken));
        }
        private async Task ProcessDocumentQueueAsync(
            Document document,
            List <ValueTuple <SymbolAndProjectId, IReferenceFinder> > documentQueue,
            ProgressWrapper wrapper)
        {
            await _progress.OnFindInDocumentStartedAsync(document).ConfigureAwait(false);

            SemanticModel model = null;

            try
            {
                model = await document.GetSemanticModelAsync(_cancellationToken).ConfigureAwait(false);

                // start cache for this semantic model
                FindReferenceCache.Start(model);

#if PARALLEL
                Roslyn.Utilities.TaskExtensions.RethrowIncorrectAggregateExceptions(cancellationToken, () =>
                {
                    documentQueue.AsParallel().WithCancellation(cancellationToken).ForAll(symbolAndFinder =>
                    {
                        var symbol = symbolAndFinder.Item1;
                        var finder = symbolAndFinder.Item2;

                        ProcessDocument(document, symbol, finder, wrapper);
                    });
                });
#else
                foreach (var symbolAndFinder in documentQueue)
                {
                    var symbol = symbolAndFinder.Item1;
                    var finder = symbolAndFinder.Item2;

                    await ProcessDocumentAsync(document, symbol, finder, wrapper).ConfigureAwait(false);
                }
#endif
            }
            finally
            {
                FindReferenceCache.Stop(model);

                await _progress.OnFindInDocumentCompletedAsync(document).ConfigureAwait(false);
            }
        }
Esempio n. 5
0
        public static async Task <IEnumerable <SyntaxToken> > GetConstructorInitializerTokensAsync(this Document document, CancellationToken cancellationToken)
        {
            // model should exist already
            if (!document.TryGetSemanticModel(out var model))
            {
                return(Contract.FailWithReturn <IEnumerable <SyntaxToken> >("we should never reach here"));
            }

            var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            if (syntaxFacts == null)
            {
                return(SpecializedCollections.EmptyEnumerable <SyntaxToken>());
            }

            return(FindReferenceCache.GetConstructorInitializerTokens(syntaxFacts, model, root, cancellationToken));
        }
Esempio n. 6
0
        internal static async Task <IEnumerable <SyntaxToken> > GetIdentifierOrGlobalNamespaceTokensWithTextAsync(
            this Document document, string identifier, CancellationToken cancellationToken)
        {
            // model should exist already
            SemanticModel model;

            if (!document.TryGetSemanticModel(out model))
            {
                return(Contract.FailWithReturn <IEnumerable <SyntaxToken> >("we should never reach here"));
            }

            // It's very costly to walk an entire tree.  So if the tree is simple and doesn't contain
            // any unicode escapes in it, then we do simple string matching to find the tokens.
            var info = await SyntaxTreeInfo.GetIdentifierInfoAsync(document, cancellationToken).ConfigureAwait(false);

            if (!info.ProbablyContainsIdentifier(identifier))
            {
                return(SpecializedCollections.EmptyEnumerable <SyntaxToken>());
            }

            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            if (syntaxFacts == null)
            {
                return(SpecializedCollections.EmptyEnumerable <SyntaxToken>());
            }

            var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var version = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);

            SourceText text = null;

            if (!info.ProbablyContainsEscapedIdentifier(identifier))
            {
                text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
            }

            return(FindReferenceCache.GetIdentifierOrGlobalNamespaceTokensWithText(syntaxFacts, document, version, model, root, text, identifier, cancellationToken));
        }