Example #1
0
        internal static async Task <Solution> RenameAsync(
            RenameLocations locations,
            string newName,
            Func <Location, bool> filter = null,
            Func <IEnumerable <ISymbol>, bool?> hasConflict = null,
            CancellationToken cancellationToken             = default)
        {
            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentException(nameof(newName));
            }

            cancellationToken.ThrowIfCancellationRequested();

            var symbolAndProjectId = locations.SymbolAndProjectId;

            if (filter != null)
            {
                locations = new RenameLocations(
                    locations.Locations.Where(loc => filter(loc.Location)).ToSet(),
                    symbolAndProjectId, locations.Solution,
                    locations.ReferencedSymbols, locations.ImplicitLocations.Where(loc => filter(loc.Location)),
                    locations.Options);
            }

            var conflictResolution = await ConflictResolver.ResolveConflictsAsync(
                locations, symbolAndProjectId.Symbol.Name, newName, locations.Options, hasConflict, cancellationToken).ConfigureAwait(false);

            return(conflictResolution.NewSolution);
        }
Example #2
0
        internal static async Task<Solution> RenameAsync(
            RenameLocations locations,
            string newName,
            Func<Location, bool> filter = null,
            Func<IEnumerable<ISymbol>, bool?> hasConflict = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentException(nameof(newName));
            }

            cancellationToken.ThrowIfCancellationRequested();

            var symbol = locations.Symbol;
            if (filter != null)
            {
                locations = new RenameLocations(
                    locations.Locations.Where(loc => filter(loc.Location)).ToSet(),
                    symbol, locations.Solution,
                    locations.ReferencedSymbols, locations.ImplicitLocations,
                    locations.Options);
            }

            var conflictResolution = await ConflictResolver.ResolveConflictsAsync(
                locations, symbol.Name, newName, locations.Options, hasConflict, cancellationToken).ConfigureAwait(false);

            return conflictResolution.NewSolution;
        }
 public InlineRenameLocationSet(SymbolInlineRenameInfo renameInfo, RenameLocations renameLocationSet)
 {
     _renameInfo = renameInfo;
     _renameLocationSet = renameLocationSet;
     this.Locations = renameLocationSet.Locations.Where(RenameLocation.ShouldRename)
                                                 .Select(ConvertLocation)
                                                 .ToImmutableArray();
 }
        /// <summary>
        /// Find the locations that need to be renamed.
        /// </summary>
        internal static async Task <RenameLocations> FindAsync(ISymbol symbol, Solution solution, OptionSet optionSet, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(symbol);
            using (Logger.LogBlock(FunctionId.Rename_AllRenameLocations, cancellationToken))
            {
                symbol = await ReferenceProcessing.FindDefinitionSymbolAsync(symbol, solution, cancellationToken).ConfigureAwait(false);

                var originalSymbolResult = await AddLocationsReferenceSymbolsAsync(symbol, solution, cancellationToken).ConfigureAwait(false);

                var intermediateResult = new RenameLocations(symbol, solution, optionSet, originalSymbolResult, overloadsResult: null, stringsResult: null, commentsResult: null);

                return(await intermediateResult.FindWithUpdatedOptionsAsync(optionSet, cancellationToken).ConfigureAwait(false));
            }
        }
Example #5
0
        internal static async Task <Solution> RenameAsync(
            RenameLocations locations,
            string newName,
            ImmutableHashSet <ISymbol> nonConflictSymbols = null,
            CancellationToken cancellationToken           = default)
        {
            Contract.ThrowIfTrue(string.IsNullOrEmpty(newName));

            cancellationToken.ThrowIfCancellationRequested();

            var conflictResolution = await locations.ResolveConflictsAsync(
                newName, nonConflictSymbols, cancellationToken).ConfigureAwait(false);

            return(conflictResolution.NewSolution);
        }
Example #6
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));
        }
Example #7
0
        internal static Task <RenameLocations> GetRenameLocationsAsync(Solution solution, ISymbol symbol, OptionSet options, CancellationToken cancellationToken)
        {
            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }

            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            cancellationToken.ThrowIfCancellationRequested();

            options = options ?? solution.Options;
            return(RenameLocations.FindAsync(symbol, solution, options, cancellationToken));
        }
Example #8
0
        internal static async Task <Solution> RenameAsync(
            RenameLocations locations,
            string newName,
            ImmutableHashSet <ISymbol> nonConflictSymbols = null,
            CancellationToken cancellationToken           = default)
        {
            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentException(nameof(newName));
            }

            cancellationToken.ThrowIfCancellationRequested();

            var conflictResolution = await ConflictResolver.ResolveConflictsAsync(
                locations, newName, nonConflictSymbols, cancellationToken).ConfigureAwait(false);

            return(conflictResolution.NewSolution);
        }
Example #9
0
 internal static Task <RenameLocations> FindRenameLocationsAsync(Solution solution, ISymbol symbol, RenameOptionSet optionSet, CancellationToken cancellationToken)
 => RenameLocations.FindLocationsAsync(symbol, solution, optionSet, cancellationToken);
Example #10
0
        /// <summary>
        /// Find the locations that need to be renamed.
        /// </summary>
        internal static async Task<RenameLocations> FindAsync(ISymbol symbol, Solution solution, OptionSet optionSet, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(symbol);
            using (Logger.LogBlock(FunctionId.Rename_AllRenameLocations, cancellationToken))
            {
                symbol = await ReferenceProcessing.FindDefinitionSymbolAsync(symbol, solution, cancellationToken).ConfigureAwait(false);
                var originalSymbolResult = await AddLocationsReferenceSymbolsAsync(symbol, solution, cancellationToken).ConfigureAwait(false);
                var intermediateResult = new RenameLocations(symbol, solution, optionSet, originalSymbolResult, overloadsResult: null, stringsResult: null, commentsResult: null);

                return await intermediateResult.FindWithUpdatedOptionsAsync(optionSet, cancellationToken).ConfigureAwait(false);
            }
        }
Example #11
0
 internal static Task <RenameLocations> FindRenameLocationsAsync(
     Solution solution, ISymbol symbol, OptionSet optionSet, CancellationToken cancellationToken)
 {
     return(RenameLocations.FindLocationsAsync(
                symbol, solution, RenameOptionSet.From(solution, optionSet), cancellationToken));
 }
 public InlineRenameLocationSet(SymbolInlineRenameInfo renameInfo, RenameLocations renameLocationSet)
 {
     _renameInfo = renameInfo;
     _renameLocationSet = renameLocationSet;
     this.Locations = renameLocationSet.Locations.Where(l => !l.IsCandidateLocation || l.IsMethodGroupReference).Select(ConvertLocation).ToList();
 }