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()))); } }
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()))); } }
public async Task <RenameLocationSet> FindWithUpdatedOptionsAsync(OptionSet optionSet, CancellationToken cancellationToken) { Contract.ThrowIfNull(this.optionSet, "FindWithUpdatedOptionsAsync can only be called on a result of FindAsync"); using (Logger.LogBlock(FeatureId.Rename, FunctionId.Rename_AllRenameLocations, cancellationToken)) { var overloadsResult = optionSet.GetOption(RenameOptions.RenameOverloads) && this.overloadsResult == null ? await GetOverloadsAsync(this.symbol, this.solution, cancellationToken).ConfigureAwait(false) : null; var stringsAndComments = await ReferenceProcessing.GetRenamableLocationsInStringsAndCommentsAsync( this.symbol, this.solution, optionSet.GetOption(RenameOptions.RenameInStrings) && this.stringsResult == null, optionSet.GetOption(RenameOptions.RenameInComments) && this.commentsResult == null, cancellationToken).ConfigureAwait(false); return(new RenameLocationSet(symbol, solution, optionSet, originalSymbolResult, overloadsResult != null ? overloadsResult : this.overloadsResult, stringsAndComments.Item1 != null ? stringsAndComments.Item1 : this.stringsResult, stringsAndComments.Item2 != null ? stringsAndComments.Item2 : this.commentsResult)); } }
/// <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)); } }
public async Task <RenameLocationSet> FindWithUpdatedOptionsAsync(OptionSet optionSet, CancellationToken cancellationToken) { Contract.ThrowIfNull(_optionSet, "FindWithUpdatedOptionsAsync can only be called on a result of FindAsync"); using (Logger.LogBlock(FunctionId.Rename_AllRenameLocations, cancellationToken)) { var overloadsResult = _overloadsResult ?? (optionSet.GetOption(RenameOptions.RenameOverloads) ? await GetOverloadsAsync(_symbol, _solution, cancellationToken).ConfigureAwait(false) : null); var stringsAndComments = await ReferenceProcessing.GetRenamableLocationsInStringsAndCommentsAsync( _symbol, _solution, _originalSymbolResult.Locations, optionSet.GetOption(RenameOptions.RenameInStrings) && _stringsResult == null, optionSet.GetOption(RenameOptions.RenameInComments) && _commentsResult == null, cancellationToken).ConfigureAwait(false); return(new RenameLocationSet(_symbol, _solution, optionSet, _originalSymbolResult, _overloadsResult ?? overloadsResult, _stringsResult ?? stringsAndComments.Item1, _commentsResult ?? stringsAndComments.Item2)); } }