예제 #1
0
        internal static async Task FindLiteralReferencesAsync(
            object value,
            TypeCode typeCode,
            Solution solution,
            IStreamingFindLiteralReferencesProgress progress,
            CancellationToken cancellationToken)
        {
            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 FindLiteralsServerCallback(solution, progress);

                    _ = await client.TryInvokeAsync <IRemoteSymbolFinderService>(
                        solution,
                        (service, solutionInfo, callbackId, cancellationToken) => service.FindLiteralReferencesAsync(solutionInfo, callbackId, value, typeCode, cancellationToken),
                        serverCallback,
                        cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    await FindLiteralReferencesInCurrentProcessAsync(value, solution, progress, cancellationToken).ConfigureAwait(false);
                }
            }
        }
예제 #2
0
        private static async Task <bool> TryFindLiteralReferencesInServiceProcessAsync(
            object value,
            Solution solution,
            IStreamingFindLiteralReferencesProgress progress,
            CancellationToken cancellationToken)
        {
            var client = await solution.Workspace.GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);

            if (client == null)
            {
                return(false);
            }

            // 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 FindLiteralsServerCallback(solution, progress, cancellationToken);

            using (var session = await client.TryCreateCodeAnalysisServiceSessionAsync(
                       solution, serverCallback, cancellationToken).ConfigureAwait(false))
            {
                if (session == null)
                {
                    return(false);
                }

                await session.InvokeAsync(
                    nameof(IRemoteSymbolFinder.FindLiteralReferencesAsync),
                    value).ConfigureAwait(false);
            }

            return(true);
        }
        internal static async Task FindLiteralReferencesAsync(
            object value,
            TypeCode typeCode,
            Solution solution,
            IStreamingFindLiteralReferencesProgress progress,
            CancellationToken cancellationToken)
        {
            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 FindLiteralsServerCallback(solution, progress, cancellationToken);

                    var success = await client.TryRunRemoteAsync(
                        WellKnownServiceHubServices.CodeAnalysisService,
                        nameof(IRemoteSymbolFinder.FindLiteralReferencesAsync),
                        new object[] { value, typeCode },
                        solution,
                        serverCallback,
                        cancellationToken).ConfigureAwait(false);

                    if (success)
                    {
                        return;
                    }
                }

                await FindLiteralReferencesInCurrentProcessAsync(value, solution, progress, cancellationToken).ConfigureAwait(false);
            }
        }
예제 #4
0
        private static async Task <bool> TryFindLiteralReferencesInServiceProcessAsync(
            object value,
            TypeCode typeCode,
            Solution solution,
            IStreamingFindLiteralReferencesProgress progress,
            CancellationToken cancellationToken)
        {
            // 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 FindLiteralsServerCallback(solution, progress, cancellationToken);

            return(await solution.TryRunCodeAnalysisRemoteAsync(
                       serverCallback,
                       nameof(IRemoteSymbolFinder.FindLiteralReferencesAsync),
                       new object[] { value, typeCode },
                       cancellationToken).ConfigureAwait(false));
        }