private static async Task <RenameLocations> FindLocationsInCurrentProcessAsync( ISymbol symbol, Solution solution, SymbolRenameOptions options, CodeCleanupOptionsProvider cleanupOptions, CancellationToken cancellationToken) { Contract.ThrowIfNull(symbol); using (Logger.LogBlock(FunctionId.Rename_AllRenameLocations, cancellationToken)) { symbol = await ReferenceProcessing.FindDefinitionSymbolAsync(symbol, solution, cancellationToken).ConfigureAwait(false); // First, find the direct references just to the symbol being renamed. var originalSymbolResult = await AddLocationsReferenceSymbolsAsync(symbol, solution, cancellationToken).ConfigureAwait(false); // Next, find references to overloads, if the user has asked to rename those as well. var overloadsResult = options.RenameOverloads ? await GetOverloadsAsync(symbol, solution, cancellationToken).ConfigureAwait(false) : ImmutableArray <SearchResult> .Empty; // Finally, include strings/comments if that's what the user wants. var(strings, comments) = await ReferenceProcessing.GetRenamableLocationsInStringsAndCommentsAsync( symbol, solution, originalSymbolResult.Locations, options.RenameInStrings, options.RenameInComments, cancellationToken).ConfigureAwait(false); var mergedLocations = ImmutableHashSet.CreateBuilder <RenameLocation>(); using var _1 = ArrayBuilder <ISymbol> .GetInstance(out var mergedReferencedSymbols); using var _2 = ArrayBuilder <ReferenceLocation> .GetInstance(out var mergedImplicitLocations); var renameMethodGroupReferences = options.RenameOverloads || !GetOverloadedSymbols(symbol).Any(); foreach (var result in overloadsResult.Concat(originalSymbolResult)) { mergedLocations.AddRange(renameMethodGroupReferences ? result.Locations : result.Locations.Where(x => x.CandidateReason != CandidateReason.MemberGroup)); mergedImplicitLocations.AddRange(result.ImplicitLocations); mergedReferencedSymbols.AddRange(result.ReferencedSymbols); } // Add string and comment locations to the merged hashset // after adding in reference symbols. This allows any references // in comments to be resolved as proper references rather than // comment resolutions. See https://github.com/dotnet/roslyn/issues/54294 mergedLocations.AddRange(strings.NullToEmpty()); mergedLocations.AddRange(comments.NullToEmpty()); return(new RenameLocations( symbol, solution, options, cleanupOptions, new SearchResult( mergedLocations.ToImmutable(), mergedImplicitLocations.ToImmutable(), mergedReferencedSymbols.ToImmutable()))); } }
/// <summary> /// Find the locations that need to be renamed. /// </summary> internal static async Task <RenameLocations> FindAsync( SymbolAndProjectId symbolAndProjectId, Solution solution, OptionSet optionSet, CancellationToken cancellationToken) { Contract.ThrowIfNull(symbolAndProjectId.Symbol); using (Logger.LogBlock(FunctionId.Rename_AllRenameLocations, cancellationToken)) { symbolAndProjectId = await ReferenceProcessing.FindDefinitionSymbolAsync(symbolAndProjectId, solution, cancellationToken).ConfigureAwait(false); var originalSymbolResult = await AddLocationsReferenceSymbolsAsync(symbolAndProjectId, solution, cancellationToken).ConfigureAwait(false); var intermediateResult = new RenameLocations( symbolAndProjectId, solution, optionSet, originalSymbolResult, overloadsResult: default, stringsResult: default, commentsResult: default);
private static async Task <RenameLocations> FindLocationsInCurrentProcessAsync( ISymbol symbol, Solution solution, RenameOptionSet optionSet, CancellationToken cancellationToken) { Contract.ThrowIfNull(symbol); using (Logger.LogBlock(FunctionId.Rename_AllRenameLocations, cancellationToken)) { symbol = await ReferenceProcessing.FindDefinitionSymbolAsync(symbol, solution, cancellationToken).ConfigureAwait(false); // First, find the direct references just to the symbol being renamed. var originalSymbolResult = await AddLocationsReferenceSymbolsAsync(symbol, solution, cancellationToken).ConfigureAwait(false); // Next, find references to overloads, if the user has asked to rename those as well. var overloadsResult = await GetOverloadsAsync(symbol, solution, optionSet, cancellationToken).ConfigureAwait(false); // Finally, include strings/comments if that's what the user wants. var(strings, comments) = await ReferenceProcessing.GetRenamableLocationsInStringsAndCommentsAsync( symbol, solution, originalSymbolResult.Locations, optionSet.RenameInStrings, optionSet.RenameInComments, cancellationToken).ConfigureAwait(false); var mergedLocations = ImmutableHashSet.CreateBuilder <RenameLocation>(); using var _1 = ArrayBuilder <ISymbol> .GetInstance(out var mergedReferencedSymbols); using var _2 = ArrayBuilder <ReferenceLocation> .GetInstance(out var mergedImplicitLocations); mergedLocations.AddRange(strings.NullToEmpty()); mergedLocations.AddRange(comments.NullToEmpty()); var renameMethodGroupReferences = optionSet.RenameOverloads || !GetOverloadedSymbols(symbol).Any(); foreach (var result in overloadsResult.Concat(originalSymbolResult)) { mergedLocations.AddRange(renameMethodGroupReferences ? result.Locations : result.Locations.Where(x => x.CandidateReason != CandidateReason.MemberGroup)); mergedImplicitLocations.AddRange(result.ImplicitLocations); mergedReferencedSymbols.AddRange(result.ReferencedSymbols); } return(new RenameLocations( symbol, solution, optionSet, new SearchResult( mergedLocations.ToImmutable(), mergedImplicitLocations.ToImmutable(), mergedReferencedSymbols.ToImmutable()))); } }
/// <summary> /// Find the locations that need to be renamed. /// </summary> public static async Task <RenameLocationSet> 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 RenameLocationSet(symbol, solution, optionSet, originalSymbolResult, overloadsResult: null, stringsResult: null, commentsResult: null); return(await intermediateResult.FindWithUpdatedOptionsAsync(optionSet, cancellationToken).ConfigureAwait(false)); } }
/// <summary> /// Find the locations that need to be renamed. /// </summary> public static async Task <RenameLocationSet> FindAsync(ISymbol symbol, Solution solution, OptionSet optionSet, CancellationToken cancellationToken) { Contract.ThrowIfNull(symbol); using (Logger.LogBlock(FeatureId.Rename, FunctionId.Rename_AllRenameLocations, cancellationToken)) { symbol = await ReferenceProcessing.FindDefinitionSymbolAsync(symbol, solution, cancellationToken).ConfigureAwait(false); var originalSymbolResult = await AddLocationsReferenceSymbolsAsync(symbol, solution, cancellationToken).ConfigureAwait(false); var overloadsResult = optionSet.GetOption(RenameOptions.RenameOverloads) ? await GetOverloadsAsync(symbol, solution, cancellationToken).ConfigureAwait(false) : null; var stringsAndComments = await ReferenceProcessing.GetRenamableLocationsInStringsAndCommentsAsync( symbol, solution, optionSet.GetOption(RenameOptions.RenameInStrings), optionSet.GetOption(RenameOptions.RenameInComments), cancellationToken).ConfigureAwait(false); return(new RenameLocationSet(symbol, solution, optionSet, originalSymbolResult, overloadsResult, stringsAndComments.Item1, stringsAndComments.Item2)); } }