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.87k stars 4.01k forks source link

Adding/Removing space when toggling line comments #73796

Open Lord-Turmoil opened 3 months ago

Lord-Turmoil commented 3 months ago

This issue was originally posted in Provide VS Code-like toggle comment in Visual Studio of Developer Community.

Summary

As Visual Studio 2022 Preview introduced Ctrl + / as the default shortcut for toggling line comments, it reminds me of this long-existing issue that is quite annoying.

In Visual Studio, the behavior of toggling line comment will not add space between // and the code and will not trim the space when uncommenting the code if there is any.

//int a = 1;
 int a = 1;

However, Visual Studio Code and other IDEs like JetBrains will, which I think could be better.

// int a = 1;
int a = 1;

This small detail significantly impacts the overall code style and requires extra effort to manually add or remove spaces in Visual Studio.

Proposed Feature

I suppose there shouldn't be any technical problem, just an editor action to add/remove the space when toggling a line comment.

sharwell commented 2 months ago

I don't have strong thoughts about what to do for the Toggle Comment command. However, for Edit.CommentSelection, I don't believe we should make this change as it will negatively impact StyleCop users who invoke this command twice to comment out code blocks with //// and simultaneously distinguish them from commented text.

In general, I believe that only true comments (and not commented code) should have a preceding space.

CyrusNajmabadi commented 2 months ago

I'd prefer to not change this at all. Not without substantially more feedback