Skip to content

Commit

Permalink
Merge pull request #55747 from ryzngard/issues/54294_rename_comment_c…
Browse files Browse the repository at this point in the history
…onflict

Prefer symbol references in InlineRename
  • Loading branch information
ryzngard authored Aug 20, 2021
2 parents 00e6420 + 2450c8c commit ab54a0f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/EditorFeatures/Test2/Rename/InlineRenameTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2165,5 +2165,37 @@ class [|C|]
Await VerifyTagsAreCorrect(workspace, "BarGoo")
End Using
End Function

<WpfTheory>
<CombinatorialData, Trait(Traits.Feature, Traits.Features.Rename)>
Public Async Function RenameInComment(host As RenameTestHost) As Task
Using workspace = CreateWorkspaceWithWaiter(
<Workspace>
<Project Language="C#" CommonReferences="true" LanguageVersion="preview">
<Document>
class [|$$MyClass|]
{
/// <summary>
/// Initializes <see cref="MyClass"/>;
/// </summary>
MyClass()
{
}
}
</Document>
</Project>
</Workspace>, host)

Dim session = StartSession(workspace)

session.ApplyReplacementText("Example", True)
session.RefreshRenameSessionWithOptionsChanged(RenameOptions.RenameInComments, True)

session.Commit()

Await VerifyTagsAreCorrect(workspace, "Example")
End Using
End Function

End Class
End Namespace
10 changes: 7 additions & 3 deletions src/Workspaces/Core/Portable/Rename/RenameLocations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ private static async Task<RenameLocations> FindLocationsInCurrentProcessAsync(
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))
{
Expand All @@ -146,6 +143,13 @@ private static async Task<RenameLocations> FindLocationsInCurrentProcessAsync(
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, optionSet,
new SearchResult(
Expand Down

0 comments on commit ab54a0f

Please sign in to comment.