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
        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));
        }