コード例 #1
0
        private static async Task <bool> TryFindReferencesInServiceProcessAsync(
            SymbolAndProjectId symbolAndProjectId,
            Solution solution,
            IStreamingFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            // If ProjectId is null then this is a call through our old public API.  We don't have
            // the necessary data to effectively run the call out of proc.
            if (symbolAndProjectId.ProjectId != 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);

                return(await solution.TryRunCodeAnalysisRemoteAsync(
                           serverCallback,
                           nameof(IRemoteSymbolFinder.FindReferencesAsync),
                           new object[]
                {
                    SerializableSymbolAndProjectId.Dehydrate(symbolAndProjectId),
                    documents?.Select(d => d.Id).ToArray(),
                    SerializableFindReferencesSearchOptions.Dehydrate(options),
                },
                           cancellationToken).ConfigureAwait(false));
            }

            return(false);
        }
コード例 #2
0
        private static async Task FindReferencesInServiceProcessAsync(
            SymbolAndProjectId symbolAndProjectId,
            Solution solution,
            IStreamingFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            CancellationToken cancellationToken)
        {
            var client = await solution.Workspace.GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);

            if (client == null)
            {
                await FindReferencesInCurrentProcessAsync(
                    symbolAndProjectId, solution, progress, documents, cancellationToken).ConfigureAwait(false);

                return;
            }

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

            await client.RunCodeAnalysisServiceOnRemoteHostAsync(
                solution, serverCallback,
                nameof(IRemoteSymbolFinder.FindReferencesAsync),
                new object[] { SerializableSymbolAndProjectId.Dehydrate(symbolAndProjectId), documents?.Select(d => d.Id).ToArray() },
                cancellationToken).ConfigureAwait(false);
        }
コード例 #3
0
        internal static async Task FindReferencesAsync(
            SymbolAndProjectId symbolAndProjectId,
            Solution solution,
            IStreamingFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.FindReference, cancellationToken))
            {
                // If ProjectId is null then this is a call through our old public API.  We don't have
                // the necessary data to effectively run the call out of proc.
                if (symbolAndProjectId.ProjectId != 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(
                            WellKnownServiceHubServices.CodeAnalysisService,
                            nameof(IRemoteSymbolFinder.FindReferencesAsync),
                            solution,
                            new object[]
                        {
                            SerializableSymbolAndProjectId.Dehydrate(symbolAndProjectId),
                            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(
                    symbolAndProjectId, solution, progress,
                    documents, options, cancellationToken).ConfigureAwait(false);
            }
        }
コード例 #4
0
        internal static async Task FindReferencesAsync(
            ISymbol symbol,
            Solution solution,
            IStreamingFindReferencesProgress progress,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution.GetOriginatingProjectId(symbol), WorkspacesResources.Symbols_project_could_not_be_found_in_the_provided_solution);

            using (Logger.LogBlock(FunctionId.FindReference, cancellationToken))
            {
                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(
                        WellKnownServiceHubServices.CodeAnalysisService,
                        nameof(IRemoteSymbolFinder.FindReferencesAsync),
                        solution,
                        new object[]
                    {
                        SerializableSymbolAndProjectId.Dehydrate(solution, symbol, 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);
            }
        }
コード例 #5
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);
            }
        }