예제 #1
0
        private static async Task AddMetadataDeclarationsWithNormalQueryAsync(
            Project project,
            IAssemblySymbol assembly,
            PortableExecutableReference?reference,
            SearchQuery query,
            SymbolFilter filter,
            ArrayBuilder <ISymbol> list,
            CancellationToken cancellationToken)
        {
            // All entrypoints to this function are Find functions that are only searching
            // for specific strings (i.e. they never do a custom search).
            Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");

            using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken))
            {
                if (reference != null)
                {
                    var info = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync(
                        project.Solution, reference, loadOnly : false, cancellationToken).ConfigureAwait(false);

                    // We must have an index since we passed in loadOnly: false here.
                    Contract.ThrowIfNull(info);

                    var symbols = await info.FindAsync(query, assembly, filter, cancellationToken).ConfigureAwait(false);

                    list.AddRange(symbols);
                }
            }
        }
예제 #2
0
        private static async Task AddMatchingMetadataTypesInMetadataReferenceAsync(
            SymbolSet metadataTypes,
            Project project,
            Func <INamedTypeSymbol, SymbolSet, bool> typeMatches,
            Compilation compilation,
            PortableExecutableReference reference,
            SymbolSet result,
            CancellationToken cancellationToken
            )
        {
            cancellationToken.ThrowIfCancellationRequested();

            // We store an index in SymbolTreeInfo of the *simple* metadata type name
            // to the names of the all the types that either immediately derive or
            // implement that type.  Because the mapping is from the simple name
            // we might get false positives.  But that's fine as we still use
            // 'tpeMatches' to make sure the match is correct.
            var symbolTreeInfo = await SymbolTreeInfo
                                 .GetInfoForMetadataReferenceAsync(
                project.Solution,
                reference,
                loadOnly : false,
                cancellationToken : cancellationToken
                )
                                 .ConfigureAwait(false);

            // For each type we care about, see if we can find any derived types
            // in this index.
            foreach (var metadataType in metadataTypes)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var baseTypeName = metadataType.Name;

                // For each derived type we find, see if we can map that back
                // to an actual symbol.  Then check if that symbol actually fits
                // our criteria.
                foreach (
                    var derivedType in symbolTreeInfo.GetDerivedMetadataTypes(
                        baseTypeName,
                        compilation,
                        cancellationToken
                        )
                    )
                {
                    if (
                        derivedType != null &&
                        derivedType.Locations.Any(s_isInMetadata) &&
                        typeMatches(derivedType, metadataTypes)
                        )
                    {
                        result.Add(derivedType);
                    }
                }
            }
        }
예제 #3
0
        private static async Task AddDeclarationsAsync(
            Solution solution, IAssemblySymbol assembly, PortableExecutableReference referenceOpt, SearchQuery query, SymbolFilter filter, List <ISymbol> list, CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken))
            {
                if (referenceOpt != null)
                {
                    var info = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync(
                        solution, referenceOpt, loadOnly : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                    if (info != null)
                    {
                        var symbols = await info.FindAsync(query, assembly, cancellationToken).ConfigureAwait(false);

                        list.AddRange(FilterByCriteria(symbols, filter));
                    }
                }
            }
        }
        private static async Task AddDeclarationsAsync(
            Solution solution, IAssemblySymbol assembly, PortableExecutableReference referenceOpt,
            SearchQuery query, SymbolFilter filter, ArrayBuilder <ISymbol> list, CancellationToken cancellationToken)
        {
            // All entrypoints to this function are Find functions that are only searching
            // for specific strings (i.e. they never do a custom search).
            Debug.Assert(query.Kind != SearchKind.Custom);

            using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken))
            {
                if (referenceOpt != null)
                {
                    var info = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync(
                        solution, referenceOpt, loadOnly : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                    if (info != null)
                    {
                        var symbols = await info.FindAsync(query, assembly, filter, cancellationToken).ConfigureAwait(false);

                        list.AddRange(symbols);
                    }
                }
            }
        }