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.06k stars 4.04k forks source link

code formatting: keep position of rest-of-line comment start if possible #52501

Open vsfeedback opened 3 years ago

vsfeedback commented 3 years ago

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


[severity:It bothers me. A fix would be nice] I'd like the start of a rest-of-line comment (starts with // in C#, and with ' in VB.NET) to stay at the same position when code before the comment gets reformatted.

It did/does so in Visual Studio 6 and the Excel Visual Basic editor.

Examples - first what I've been used to for years, and what I'd like to have again:

VBA6 (Excel 2010), before

Public Enum TestEnum
    None=0      ' default, invalid
End Enum

VBA6 (Excel 2010), after (Beautification of code occurs automatically as soon as the insertion mark leaves the code line.)

Public Enum TestEnum
    None = 0    ' default, invalid
End Enum

(as you see, the ' stays below the capital E of "TestEnum")

VB6 (1999/2999), before

Public Enum TestEnum
    None=0      ' default, invalid
End Enum

VB6 (1999/2999), after (Beautification of code occurs automatically as soon as the insertion mark leaves the code line.)

Public Enum TestEnum
    None = 0    ' default, invalid
End Enum

Same as above.

Only when there's not enough space after the beautified code (at least one space), the comments get shifted to the right here in Visual Studio 6 and the VBA6 editor.

Now for the new behavior (Microsoft Visual Studio Community 2019, Version 16.9.2):

VB.NET, before

    Public Enum TestEnum
        None=0      ' default; invalid
    End Enum

VB.NET, after (Beautification of code occurs automatically as soon as the insertion mark leaves the code line.)

    Public Enum TestEnum
        None = 0      ' default; invalid
    End Enum

C#, before

        public enum TestEnum {
            None=0,     // default, invalid
        }

C#, after (Beautification of code occurs after copy/repaste or replacing e. g. the closing curly brace with another closing curly brace)

        public enum TestEnum {
            None = 0,     // default, invalid
        }

As you see, the comments have been shifted to the right, one position for each inserted space.

When otoh spaces get deleted, the comments stay where they are in VB(A)6, but are shifted to the left in Visual Studio 2019.

Anything but severe, but requires a bit more of superfluous effort to place comments aligned with one another.


Original Comments

Feedback Bot on 3/22/2021, 10:49 PM:

Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We'll provide an update once the issue has been triaged by the product team.

CyrusNajmabadi commented 3 years ago

I can't repro this at all.

jmarolf commented 3 years ago

Design Review

Talked about what we do today as well as if this behavior was desirable. Discussion was relatively short. Will mark as help-wanted as the behavior is desirable even if it may be difficult to accomplish. Any contributor who want to work on this should start a discussion in https://github.com/dotnet/roslyn/discussions to outline their approach and/or get assistance from the team.