Ejemplo n.º 1
0
        internal static async Task FindReferencesAsync(
            ISymbol symbol,
            Solution solution,
            IStreamingFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.FindReference, cancellationToken))
            {
                var project = solution.GetOriginatingProject(symbol);
                if (project != null)
                {
                    var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                    if (client != null)
                    {
                        // Create a callback that we can pass to the server process to hear about the
                        // results as it finds them.  When we hear about results we'll forward them to
                        // the 'progress' parameter which will then update the UI.
                        var serverCallback = new FindReferencesServerCallback(solution, progress, cancellationToken);

                        var success = await client.TryRunRemoteAsync(
                            WellKnownServiceHubService.CodeAnalysis,
                            nameof(IRemoteSymbolFinder.FindReferencesAsync),
                            solution,
                            new object[]
                        {
                            SerializableSymbolAndProjectId.Create(symbol, project, cancellationToken),
                            documents?.Select(d => d.Id).ToArray(),
                            SerializableFindReferencesSearchOptions.Dehydrate(options),
                        },
                            serverCallback,
                            cancellationToken).ConfigureAwait(false);

                        if (success)
                        {
                            return;
                        }
                    }
                }

                // Couldn't effectively search in OOP. Perform the search in-proc.
                await FindReferencesInCurrentProcessAsync(
                    symbol, solution, progress,
                    documents, options, cancellationToken).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        internal static async Task <IEnumerable <ReferencedSymbol> > FindReferencesAsync(
            ISymbol symbol,
            Solution solution,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution.GetOriginatingProjectId(symbol), WorkspacesResources.Symbols_project_could_not_be_found_in_the_provided_solution);

            var progressCollector = new StreamingProgressCollector();

            await FindReferencesAsync(
                symbol, solution, progressCollector,
                documents : null, options, cancellationToken).ConfigureAwait(false);

            return(progressCollector.GetReferencedSymbols());
        }
        internal static Task FindReferencesInCurrentProcessAsync(
            SymbolAndProjectId symbolAndProjectId,
            Solution solution,
            IStreamingFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            var finders = ReferenceFinders.DefaultReferenceFinders;

            progress ??= NoOpStreamingFindReferencesProgress.Instance;
            var engine = new FindReferencesSearchEngine(
                solution, documents, finders, progress, options, cancellationToken);

            return(engine.FindReferencesAsync(symbolAndProjectId));
        }
Ejemplo n.º 4
0
 internal static Task <ImmutableArray <ReferencedSymbol> > FindReferencesAsync(
     ISymbol symbol,
     Solution solution,
     IFindReferencesProgress progress,
     IImmutableSet <Document> documents,
     FindReferencesSearchOptions options,
     CancellationToken cancellationToken
     )
 {
     return(SymbolFinder.FindReferencesAsync(
                symbol,
                solution,
                progress,
                documents,
                options,
                cancellationToken
                ));
 }
Ejemplo n.º 5
0
        private static async Task <ImmutableArray <ReferencedSymbol> > FindReferencesAsync(
            ISymbol symbol,
            Solution solution,
            IFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            progress ??= NoOpFindReferencesProgress.Instance;
            var streamingProgress = new StreamingProgressCollector(
                new StreamingFindReferencesProgressAdapter(progress));

            await FindReferencesAsync(
                symbol, solution, streamingProgress, documents,
                options, cancellationToken).ConfigureAwait(false);

            return(streamingProgress.GetReferencedSymbols());
        }
Ejemplo n.º 6
0
        private static async Task <IEnumerable <ReferencedSymbol> > FindReferencesAsync(
            ISymbol symbol,
            Solution solution,
            IFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution.GetOriginatingProjectId(symbol), WorkspacesResources.Symbols_project_could_not_be_found_in_the_provided_solution);

            progress ??= NoOpFindReferencesProgress.Instance;
            var streamingProgress = new StreamingProgressCollector(
                new StreamingFindReferencesProgressAdapter(progress));

            await FindReferencesAsync(
                symbol, solution, streamingProgress, documents,
                options, cancellationToken).ConfigureAwait(false);

            return(streamingProgress.GetReferencedSymbols());
        }
Ejemplo n.º 7
0
        internal static async Task <IEnumerable <ReferencedSymbol> > FindReferencesAsync(
            ISymbol symbol,
            Solution solution,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken
            )
        {
            var progressCollector = new StreamingProgressCollector();

            await FindReferencesAsync(
                symbol,
                solution,
                progressCollector,
                documents : null,
                options,
                cancellationToken
                )
            .ConfigureAwait(false);

            return(progressCollector.GetReferencedSymbols());
        }
Ejemplo n.º 8
0
        private static async Task <ImmutableArray <ReferencedSymbol> > FindCallReferencesAsync(
            Solution solution,
            ISymbol symbol,
            IImmutableSet <Document>?documents,
            CancellationToken cancellationToken = default)
        {
            if (symbol.Kind is SymbolKind.Event or
                SymbolKind.Method or
                SymbolKind.Property or
                SymbolKind.Field)
            {
                var collector = new StreamingProgressCollector();
                var options   = FindReferencesSearchOptions.GetFeatureOptionsForStartingSymbol(symbol);
                await FindReferencesAsync(
                    symbol, solution, collector, documents,
                    options, cancellationToken).ConfigureAwait(false);

                return(collector.GetReferencedSymbols());
            }

            return(ImmutableArray <ReferencedSymbol> .Empty);
        }
Ejemplo n.º 9
0
        internal static async Task FindReferencesAsync(
            ISymbol symbol,
            Solution solution,
            IStreamingFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.FindReference, cancellationToken))
            {
                if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol))
                {
                    var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                    if (client != null)
                    {
                        // Create a callback that we can pass to the server process to hear about the
                        // results as it finds them.  When we hear about results we'll forward them to
                        // the 'progress' parameter which will then update the UI.
                        var serverCallback = new FindReferencesServerCallback(solution, progress, cancellationToken);
                        var documentIds    = documents?.SelectAsArray(d => d.Id) ?? default;

                        await client.TryInvokeAsync <IRemoteSymbolFinderService>(
                            solution,
                            (service, solutionInfo, callbackId, cancellationToken) => service.FindReferencesAsync(solutionInfo, callbackId, serializedSymbol, documentIds, options, cancellationToken),
                            serverCallback,
                            cancellationToken).ConfigureAwait(false);

                        return;
                    }
                }

                // Couldn't effectively search in OOP. Perform the search in-proc.
                await FindReferencesInCurrentProcessAsync(
                    symbol, solution, progress,
                    documents, options, cancellationToken).ConfigureAwait(false);
            }
        }