Ejemplo 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));
        }
Ejemplo n.º 2
0
        private async Task ProcessDocumentWorkerAsync(Document document)
        {
            var index = await SyntaxTreeIndex.GetIndexAsync(
                document, _cancellationToken).ConfigureAwait(false);

            if (_searchKind == SearchKind.StringLiterals)
            {
                if (index.ProbablyContainsStringValue(_stringValue))
                {
                    await SearchDocumentAsync(document).ConfigureAwait(false);
                }
            }
            else if (index.ProbablyContainsInt64Value(_longValue))
            {
                await SearchDocumentAsync(document).ConfigureAwait(false);
            }
        }