dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.9k stars 4.01k forks source link

c# - Renaming a field can cause it to rename the same word in the comments in other files in the same project that are completely unrelated #74577

Open vsfeedback opened 1 month ago

vsfeedback commented 1 month ago

This issue has been moved from a ticket on Developer Community.


I had a this property in a public class: private Dispatcher Dispatcher { get; } which I renamed: private Dispatcher m_dispatcher { get; }

and it did stuff like this to other files:

/// <summary>
/// Wrapper class to provide a more reliable Dispatcher object
/// </summary>
    public static class DispatcherProvider

became

/// <summary>
/// Wrapper class to provide a more reliable m_dispatcher object
/// </summary>
    public static class DispatcherProvider

Original Comments

Feedback Bot on 5/14/2024, 10:34 PM:

(private comment, text removed)

Feedback Bot on 5/21/2024, 11:23 AM:

(private comment, text removed)

Shen Chen [MSFT] on 6/26/2024, 03:58 PM:

(private comment, text removed)

Halliday, Sean on 6/28/2024, 03:50 PM:

(private comment, text removed)


Original Solutions

(no solutions)

Cosifne commented 1 month ago

A few comments:

  1. This behavior is directly linked to this line.https://github.com/dotnet/roslyn/blob/9a792ffa3c4d8716e508863a6f87eb8464c49f45/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs#L710
  2. Customer is complaining that, when they rename a private property, the comment in other class also get renamed. We currently have many tests guarded the scenario when a public class gets renamed, all the string literal in comment should be updated. We might want to introduce another set of restrictions when the renaming symbol is private property/field/method, we should only update the string in comment within the class.
  3. If user doesn't want that now, they can turn off 'Rename in Comment' to temp disable all the comment renaming.