Exemplo n.º 1
0
 public SerializableRenameLocations Dehydrate(Solution solution, CancellationToken cancellationToken)
 => new SerializableRenameLocations
 {
     Symbol  = SerializableSymbolAndProjectId.Dehydrate(solution, Symbol, cancellationToken),
     Options = SerializableRenameOptionSet.Dehydrate(Options),
     Result  = SerializableSearchResult.Dehydrate(solution, _result, cancellationToken),
 };
Exemplo n.º 2
0
 public SerializableRenameLocations Dehydrate(Solution solution, CancellationToken cancellationToken)
 => new SerializableRenameLocations
 {
     Symbol  = SerializableSymbolAndProjectId.Dehydrate(solution, Symbol, cancellationToken),
     Options = SerializableRenameOptionSet.Dehydrate(Options),
     OriginalSymbolResult = SerializableSearchResult.Dehydrate(solution, _originalSymbolResult, cancellationToken),
     MergedResult         = SerializableSearchResult.Dehydrate(solution, _mergedResult, cancellationToken),
     OverloadsResult      = _overloadsResult.IsDefault ? null : _overloadsResult.Select(r => SerializableSearchResult.Dehydrate(solution, r, cancellationToken)).ToArray(),
     StringsResult        = _stringsResult.IsDefault ? null : _stringsResult.Select(r => SerializableRenameLocation.Dehydrate(r)).ToArray(),
     CommentsResult       = _commentsResult.IsDefault ? null : _commentsResult.Select(r => SerializableRenameLocation.Dehydrate(r)).ToArray(),
 };
Exemplo n.º 3
0
        internal static async Task <ConflictResolution> RenameSymbolAsync(
            Solution solution,
            ISymbol symbol,
            string newName,
            RenameOptionSet optionSet,
            ImmutableHashSet <ISymbol>?nonConflictSymbols,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution);
            Contract.ThrowIfNull(symbol);
            Contract.ThrowIfTrue(string.IsNullOrEmpty(newName));

            cancellationToken.ThrowIfCancellationRequested();

            using (Logger.LogBlock(FunctionId.Renamer_RenameSymbolAsync, cancellationToken))
            {
                if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol))
                {
                    var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                    if (client != null)
                    {
                        var options = SerializableRenameOptionSet.Dehydrate(optionSet);
                        var nonConflictSymbolIds = nonConflictSymbols?.SelectAsArray(s => SerializableSymbolAndProjectId.Dehydrate(solution, s, cancellationToken)) ?? default;

                        var result = await client.TryInvokeAsync <IRemoteRenamerService, SerializableConflictResolution?>(
                            solution,
                            (service, solutionInfo, cancellationToken) => service.RenameSymbolAsync(
                                solutionInfo,
                                serializedSymbol,
                                newName,
                                options,
                                nonConflictSymbolIds,
                                cancellationToken),
                            callbackTarget : null,
                            cancellationToken).ConfigureAwait(false);

                        if (result.HasValue && result.Value != null)
                        {
                            return(await result.Value.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false));
                        }

                        // TODO: do not fall back to in-proc if client is available (https://github.com/dotnet/roslyn/issues/47557)
                    }
                }
            }

            return(await RenameSymbolInCurrentProcessAsync(
                       solution, symbol, newName, optionSet,
                       nonConflictSymbols, cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 4
0
        internal static async Task <ConflictResolution> RenameSymbolAsync(
            Solution solution,
            ISymbol symbol,
            string newName,
            RenameOptionSet optionSet,
            ImmutableHashSet <ISymbol> nonConflictSymbols,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution);
            Contract.ThrowIfNull(symbol);
            Contract.ThrowIfTrue(string.IsNullOrEmpty(newName));

            cancellationToken.ThrowIfCancellationRequested();

            using (Logger.LogBlock(FunctionId.Renamer_RenameSymbolAsync, cancellationToken))
            {
                var project = solution.GetOriginatingProject(symbol);
                if (project != null)
                {
                    var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                    if (client != null)
                    {
                        var result = await client.TryRunRemoteAsync <SerializableConflictResolution>(
                            WellKnownServiceHubServices.CodeAnalysisService,
                            nameof(IRemoteRenamer.RenameSymbolAsync),
                            solution,
                            new object[]
                        {
                            SerializableSymbolAndProjectId.Create(symbol, project, cancellationToken),
                            newName,
                            SerializableRenameOptionSet.Dehydrate(optionSet),
                            nonConflictSymbols?.Select(s => SerializableSymbolAndProjectId.Dehydrate(solution, s, cancellationToken)).ToArray(),
                        },
                            callbackTarget : null,
                            cancellationToken).ConfigureAwait(false);

                        if (result.HasValue)
                        {
                            return(await result.Value.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false));
                        }
                    }
                }
            }

            return(await RenameSymbolInCurrentProcessAsync(
                       solution, symbol, newName, optionSet,
                       nonConflictSymbols, cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 5
0
        public static async Task <RenameLocations> FindLocationsAsync(
            ISymbol symbol, Solution solution, RenameOptionSet optionSet, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution);
            Contract.ThrowIfNull(symbol);

            cancellationToken.ThrowIfCancellationRequested();

            using (Logger.LogBlock(FunctionId.Renamer_FindRenameLocationsAsync, cancellationToken))
            {
                if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol))
                {
                    var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                    if (client != null)
                    {
                        var result = await client.RunRemoteAsync <SerializableRenameLocations?>(
                            WellKnownServiceHubService.CodeAnalysis,
                            nameof(IRemoteRenamer.FindRenameLocationsAsync),
                            solution,
                            new object[]
                        {
                            serializedSymbol,
                            SerializableRenameOptionSet.Dehydrate(optionSet),
                        },
                            callbackTarget : null,
                            cancellationToken).ConfigureAwait(false);

                        if (result != null)
                        {
                            var rehydrated = await RenameLocations.TryRehydrateAsync(
                                solution, result, cancellationToken).ConfigureAwait(false);

                            if (rehydrated != null)
                            {
                                return(rehydrated);
                            }
                        }
                    }
                }
            }

            // Couldn't effectively search in OOP. Perform the search in-proc.
            return(await FindLocationsInCurrentProcessAsync(
                       symbol, solution, optionSet, cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Find the locations that need to be renamed.
        /// </summary>
        public static async Task <RenameLocations> FindLocationsAsync(
            ISymbol symbol, Solution solution, RenameOptionSet optionSet, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution);
            Contract.ThrowIfNull(symbol);

            cancellationToken.ThrowIfCancellationRequested();

            using (Logger.LogBlock(FunctionId.Renamer_FindRenameLocationsAsync, cancellationToken))
            {
                if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol))
                {
                    var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                    if (client != null)
                    {
                        var options = SerializableRenameOptionSet.Dehydrate(optionSet);

                        var result = await client.TryInvokeAsync <IRemoteRenamerService, SerializableRenameLocations?>(
                            solution,
                            (service, solutionInfo, cancellationToken) => service.FindRenameLocationsAsync(solutionInfo, serializedSymbol, options, cancellationToken),
                            callbackTarget : null,
                            cancellationToken).ConfigureAwait(false);

                        if (result.HasValue && result.Value != null)
                        {
                            var rehydrated = await TryRehydrateAsync(
                                solution, result.Value, cancellationToken).ConfigureAwait(false);

                            if (rehydrated != null)
                            {
                                return(rehydrated);
                            }
                        }

                        // TODO: do not fall back to in-proc if client is available (https://github.com/dotnet/roslyn/issues/47557)
                    }
                }
            }

            // Couldn't effectively search in OOP. Perform the search in-proc.
            return(await FindLocationsInCurrentProcessAsync(
                       symbol, solution, optionSet, cancellationToken).ConfigureAwait(false));
        }