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
19.02k stars 4.03k forks source link

F2 Rename on class only selects a part of the name #75521

Open vsfeedback opened 1 week ago

vsfeedback commented 1 week ago

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


[severity:I’m unable to use this version] [regression] [worked-in:17.9]
With the following code:

public class GlobalAuthorizationAttribute : Attribute
{
    public List<GlobalUserRightEnum> RequiredRights { get; } = new List<GlobalUserRightEnum>();

public GlobalAuthorizationAttribute(params GlobalUserRightEnum[] requiredRights)
    {
        RequiredRights = requiredRights.ToList();
    }
}

Expected behavior: the whole word GlobalAuthorizationAttribute is highlighted and I can edit the end of the name to something else.

When I move the cursor to GlobalAuthorizationAttribute and click F2 Rename or Ctrl+R depends on your keyboard shortcuts setting, then the renaming is possible only in the first part.
I need to rename GlobalAuthorizationAttribute to GlobalAuthorizationAttributeBase.
This is not possible using the feature.
obrazek.png

Why do I need to do that? Because I want to create this code: obrazek.png


Original Comments

Feedback Bot on 8/11/2024, 06:17 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 8/12/2024, 07:13 AM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.

Shen Chen [MSFT] on 10/8/2024, 04:24 PM:

Hi Jan,

I understand your situation. This is a by-design scenario because we don’t want the Attributes suffix modified. We definitely want to improve this experience.
As a workaround, I tested locally if you comment out the : Attribute, then rename your class to the right name it should work. Later you can comment back the base class.
Thanks for your feedback.

Best,
Shen

Jan Seris on 10/9/2024, 07:50 AM:

OK you should improve the experience definitely. Maybe instead use analyzer and not block the renaming per se?
As for example for private fields and properties - there is a hint shown in Visual Studio but there is no blocking action to prevent that (and that’s probably expected behavior).
This is a much better solution:
obrazek.png

Cosifne commented 1 week ago

A few notes: We will need a better solution to handle renaming the Attribute suffix case. User is trying to rename

public class Ex$$ampleAttribute : Attribute

to ExampleAttribuiteBase