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