Roslyn: Cursor indentation problem after commenting a piece of code

Created on 21 Jul 2018  Â·  14Comments  Â·  Source: dotnet/roslyn

Version Used:
VS Community 2017 Version 15.7.5

Steps to Reproduce:

  1. Comment a piece of code
  2. Place the cursor at the end of the commented code
  3. Hit the "Enter" key twice (please have a look at the image)

bug

Expected Behavior:
The cursor to stay at a correct indentation level.

Actual Behavior:
The cursor jumps back to the previous indentation level.
Note that this doesn't happen on a method level or a class level. It happens inside if, foreach and other blocks.

Sorry if this has already been reported. I wasn't able to find the existing issue.

Area-IDE Bug help wanted

Most helpful comment

@CyrusNajmabadi , @jinujoseph

Note: you don't even need to do the "comment selection" command. This repros simply if you press enter underneath a commented line

There is also another wrong indentation i reported recently here. When we want to add some comments in c# code, the cursor goes to a wrong position (increased/doubled indent) after hitting two keys (for the purpose of having an empty line between the two comment lines)
scrshot-wrong-indent2-serpooshan

Note that this problem occurs only if there are some code after the comment lines (eg int i = 1; in above pic)

All 14 comments

Note: you don't even need to do the "comment selection" command. This repros simply if you press enter underneath a commented line:

indentation

I'm hitting this as well using:

Microsoft Visual Studio Enterprise 2017 Int Preview
Version 15.9.3 Preview 1.0 [28307.139.d15.9]
VisualStudio.15.IntPreview/15.9.3-pre.1.0+28307.139.d15.9
Microsoft .NET Framework
Version 4.7.03190

Installed Version: Enterprise

Application Insights Tools for Visual Studio Package   8.14.11009.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.9.04012.0
ASP.NET and Web Tools 2017

ASP.NET Core Blazor Language Services   0.7.0-rtm-20181115.1

ASP.NET Core Razor Language Services   15.8.31590
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017   5.2.60913.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.9.03024.0
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   15.9.02046.0
Azure Functions and Web Jobs Tools

C# Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service   2.0
JavaScript Language Service

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10730.2

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NuGet Package Manager   4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

Snapshot Debugging Extension   1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SQL Server Data Tools   15.1.61810.11040
Microsoft SQL Server Data Tools

TypeScript Tools   15.9.20918.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5   15.8.0.0.  Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

@CyrusNajmabadi , @jinujoseph

Note: you don't even need to do the "comment selection" command. This repros simply if you press enter underneath a commented line

There is also another wrong indentation i reported recently here. When we want to add some comments in c# code, the cursor goes to a wrong position (increased/doubled indent) after hitting two keys (for the purpose of having an empty line between the two comment lines)
scrshot-wrong-indent2-serpooshan

Note that this problem occurs only if there are some code after the comment lines (eg int i = 1; in above pic)

Why is this closed? It's still a problem in VS2019.
image

@dog44wgm

Why is this closed? It's still a problem in VS2019.

What do you mean? This issue is still open, and is still listed as "help wanted".

Why is Microsoft not fixing this bug, which exists in VS since years ? Just marking this issue with "help wanted" looks lazy to me. Shouldn't take Microsoft take some responsibility for solving old bugs in their software ?

Why is Microsoft not fixing this bug, which exists in VS since years

The issue is currently lower priority than all existing with people are working on.

Shouldn't take Microsoft take some responsibility for solving old bugs in their software ?

Age doesn't make issues more important.

Just marking this issue with "help wanted" looks lazy to me.

It's marked 'help wanted' because we would certainly take a community pr if provided.

It sounds like this is very important to you. Would you be willing to contribute a fix here? Thanks!

Would you be willing to contribute a fix here?

Roslyn is a huge codebase(needless to say). I've spent a couple dozen hours digging through it and debugging it over the years and I still have no idea where to even start if I wanted to fix this problem.
It would probably take weeks and weeks of prior experience working with the codebase to pinpoint the origin of this issue and deal with it.

That's why marking it as "help wanted" sounds like: "meh, you guys can fix it yourselves if you really want to".

With that said, if somebody was willing/had a little time to provide some guidance through the process I'd gladly give it a try.

and I still have no idea where to even start if I wanted to fix this problem.

The best place to start here would in the SmartIndet component: https://github.com/dotnet/roslyn/blob/master/src/EditorFeatures/Core/Implementation/SmartIndent/SmartIndent.cs

If you run into roadblocks there, LMK and i can try to help you through it:

That's why marking it as "help wanted" sounds like: "meh, you guys can fix it yourselves if you really want to".

Help wanted means what i said above. We would take a community PR here. Right now that this hasn't risen above the priority of all the existing work the team has. The choices are to wait until it does, or see if the community can supply a fix.

With that said, if somebody was willing/had a little time to provide some guidance through the process I'd gladly give it a try.

Yup! See above. Also, feel free to reach out on gitter.im/dotnet/roslyn or discord.gg/csharp (#roslyn channel).

Why is Microsoft not fixing this bug, which exists in VS since years

The issue is currently lower priority than all existing with people are working on.

Shouldn't take Microsoft take some responsibility for solving old bugs in their software ?

Age doesn't make issues more important.

Just marking this issue with "help wanted" looks lazy to me.

It's marked 'help wanted' because we would certainly take a community pr if provided.

It sounds like this is very important to you. Would you be willing to contribute a fix here? Thanks!

Sorry for having no experience with how VS gets maintained. However, I wonder if the right weights are given to which problem gets solved. It seemed that presently problems that get complained about a lot get most likely fixed. Which is understandable. But there is another category of problems that should get fixed, the ones which might have not so grave consequences, but nearly everybody encounters. It is sad if VS get's a bad reputation of being buggy, just because simple problems that almost everyone encounters don't get fixed. Using // comments is something every C# developer does, meaning that bug should really get fixed. I understand that the unpaid, community helpers might not want to spend their time on such a problem. But here Microsoft has a responsibility and should step in. Also, someone who has worked on that part of the Editor might solve the problem in a day or two, while someone like me who has never seen any VS code might take forever. Being that the case, I feel it is cheap from Microsoft to suggest I should fix it myself.

Which is understandable. But there is another category of problems that should get fixed, the ones which might have not so grave consequences, but nearly everybody encounters.

We call these paper-cuts, and they are def things that are fixed. But they still have to be prioritized against everything else. Every issue that is fixed is time from someone that is taken away from other things to fix. So far, this hasn't been as important to push anything else out.

Using // comments is something every C# developer does, meaning that bug should really get fixed.

This can be stated about many, if not most of all the bugs we have.

But here Microsoft has a responsibility and should step in.

We have triaged things and have assessed other issues as being more important currently. If we pull someone off to work on this, that means taking back on something else.

There isn't enough time or resources to address all the issues in a timely manner. So it will always be the case that some issues get pushed out.

Also, someone who has worked on that part of the Editor might solve the problem in a day or two,

Yes, but that means two days taken away from more important work that is more important to the community as a whole.

Being that the case, I feel it is cheap from Microsoft to suggest I should fix it myself.

This is an open source project. Many people contribute to it. One of the great benefits of this is that if you find something more important for your own needs than the team does, then it's possible for you to dive in, get your hands dirty, and solve the problems that you feel are impacting you more than the ones that we are working on.

We literally have finite time and people to work on a backlog of thousands of items. It will always be the case that whatever we pick to work on, we'll not be addressing the needs of some users. Being open source means you're not still forced to wait forever for fixes. If it's this important, then you can fix.

Note: i agree that this would take learning from someone starting out. But many contributors have done this, and given that investment they now commonly provide many features and fixes that they find important to them.

It can be done, and it's something we're happy to help you out with if you're interested.

Ive been following this issue for so long i had completely forgotten about
it.
I was getting so annoyed by this i even tried reinstalling windows.
I went to go back and check on it again recently but its somehow not doing
it any more.
Thank you for being a contributor but I agree with peterhuberSG, its been
around long enough that if it was easy, it would probably be fixed by now
and its not the kind of bug that goes away with a quick restart.

On Fri, Mar 27, 2020 at 5:49 PM CyrusNajmabadi notifications@github.com
wrote:

Which is understandable. But there is another category of problems that
should get fixed, the ones which might have not so grave consequences, but
nearly everybody encounters.

We call these paper-cuts, and they are def things that are fixed. But they
still have to be prioritized against everything else. Every issue that is
fixed is time from someone that is taken away from other things to fix. So
far, this hasn't been as important to push anything else out.

Using // comments is something every C# developer does, meaning that bug
should really get fixed.

This can be stated about many, if not most of all the bugs we have.

But here Microsoft has a responsibility and should step in.

We have triaged things and have assessed other issues as being more
important currently. If we pull someone off to work on this, that means
taking back on something else.

There isn't enough time or resources to address all the issues in a timely
manner. So it will always be the case that some issues get pushed out.

Also, someone who has worked on that part of the Editor might solve the
problem in a day or two,

Yes, but that means two days taken away from more important work that is
more important to the community as a whole.

Being that the case, I feel it is cheap from Microsoft to suggest I should
fix it myself.

This is an open source project. Many people contribute to it. One of the
great benefits of this is that if you find something more important for
your own needs than the team does, then it's possible for you to dive in,
get your hands dirty, and solve the problems that you feel are impacting
you more than the ones that we are working on.

We literally have finite time and people to work on a backlog of
thousands of items. It will always be the case that whatever we pick to
work on, we'll not be addressing the needs of some users. Being open source
means you're not still forced to wait forever for fixes. If it's this
important, then you can fix.

Note: i agree that this would take learning from someone starting out. But
many contributors have done this, and given that investment they now
commonly provide many features and fixes that they find important to them.

It can be done, and it's something we're happy to help you out with if
you're interested.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/roslyn/issues/28752#issuecomment-604843036,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACVYLEJY2YYGQ4LBQE2RKBLRJRD67ANCNFSM4FLFUEOQ
.

Have been at the vet for a few hours. can't sleep here, and i needed a distraction. so i looked into seeing if i could fix this. i might have a potential PR here.

Ok. I ended up tearing out a bunch of the existing code to go with an approach that is hopefully simpler and better. If all goes well, this won't cause any regressions in cases people care about. PR is going through CI now.

Was this page helpful?
0 / 5 - 0 ratings