示例#1
0
        protected override Task <ImmutableArray <Document> > DetermineDocumentsToSearchAsync(
            IMethodSymbol symbol,
            HashSet <string>?globalAliases,
            Project project,
            IImmutableSet <Document>?documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            return(FindDocumentsAsync(project, documents, static async(document, name, cancellationToken) =>
            {
                var index = await SyntaxTreeIndex.GetRequiredIndexAsync(document, cancellationToken).ConfigureAwait(false);
                if (index.ContainsBaseConstructorInitializer)
                {
                    return true;
                }

                if (index.ProbablyContainsIdentifier(name))
                {
                    if (index.ContainsThisConstructorInitializer)
                    {
                        return true;
                    }
                    else if (document.Project.Language == LanguageNames.VisualBasic && index.ProbablyContainsIdentifier("New"))
                    {
                        // "New" can be explicitly accessed in xml doc comments to reference a constructor.
                        return true;
                    }
                }

                return false;
            }, symbol.ContainingType.Name, cancellationToken));
        }
 /// <summary>
 /// Finds all the documents in the provided project that contain a global attribute in them.
 /// </summary>
 protected static Task <ImmutableArray <Document> > FindDocumentsWithGlobalAttributesAsync(
     Project project,
     IImmutableSet <Document>?documents,
     CancellationToken cancellationToken)
 {
     return(FindDocumentsAsync(project, documents, async(d, c) =>
     {
         var info = await SyntaxTreeIndex.GetRequiredIndexAsync(d, c).ConfigureAwait(false);
         return info.ContainsGlobalAttributes;
     }, cancellationToken));
 }
        protected static Task<ImmutableArray<Document>> FindDocumentsAsync(
            Project project,
            IImmutableSet<Document>? documents,
            PredefinedOperator op,
            CancellationToken cancellationToken)
        {
            if (op == PredefinedOperator.None)
                return SpecializedTasks.EmptyImmutableArray<Document>();

            return FindDocumentsAsync(project, documents, async (d, c) =>
            {
                var info = await SyntaxTreeIndex.GetRequiredIndexAsync(d, c).ConfigureAwait(false);
                return info.ContainsPredefinedOperator(op);
            }, cancellationToken);
        }
示例#4
0
        protected static async Task <ImmutableArray <string> > GetAllMatchingGlobalAliasNamesAsync(
            Project project, string name, int arity, CancellationToken cancellationToken)
        {
            using var result = TemporaryArray <string> .Empty;

            foreach (var document in await project.GetAllRegularAndSourceGeneratedDocumentsAsync(cancellationToken).ConfigureAwait(false))
            {
                var index = await SyntaxTreeIndex.GetRequiredIndexAsync(document, cancellationToken).ConfigureAwait(false);

                foreach (var alias in index.GetGlobalAliases(name, arity))
                {
                    result.Add(alias);
                }
            }

            return(result.ToImmutableAndClear());
        }
        /// <summary>
        /// Finds all the documents in the provided project that contain the requested string
        /// values
        /// </summary>
        protected static Task <ImmutableArray <Document> > FindDocumentsAsync(
            Project project,
            IImmutableSet <Document>?documents,
            CancellationToken cancellationToken,
            params string[] values)
        {
            return(FindDocumentsAsync(project, documents, async(d, c) =>
            {
                var info = await SyntaxTreeIndex.GetRequiredIndexAsync(d, c).ConfigureAwait(false);
                foreach (var value in values)
                {
                    if (!info.ProbablyContainsIdentifier(value))
                    {
                        return false;
                    }
                }

                return true;
            }, cancellationToken));
        }