Aspnetcore: Indentation problems with code blocks

Created on 14 Mar 2017  路  12Comments  路  Source: dotnet/aspnetcore

I wasn't sure if this should go to VS or if it belongs here (especially with the Evolution work going on.)

In Visual Studio, when auto-formatting a Razor document, a code block nested inside of an if block will cause the indentation of any code following the if block to be increased to match the indentation of the code inside of the code block.

This is driving me 馃敥 馃敥 !

bloody-razor

Moving the code out of the code block to be just inside the if block seems to clear it up:

bloody-razor-2

External area-mvc bug feature-razor-pages

Most helpful comment

Moving this out from backlog to be addressed... Let's make sure we also have good tests for this area so this will never be a thing going forward.

All 12 comments

Thanks, and yes this is a good place for you to open Razor issues. We'll investigate and communicate with the non-OSS parts of the team as necessary.

@NTaylorMullen - can you take a look at this and see what's going on?

Findings:

  • This happens in VS2017 RTM and is consistent in newer versions
  • This should be fixed in our GetDesiredIndentation service method.
  • This happens because a desired indentation doesn't get found from our SyntaxTree (it can be, we just don't do the work) and therefore falls back to the underlying C# buffer to determine the "base" indentation.

Removed investigate label.

Move out?

I spoke with @NTaylorMullen this morning - the takeaway here is that this is something we can and should fix, but with some bake time as it's going to be a little risky.

We don't currently handle indent when the cursor is positioned inside a code span. We'd need to write that logic, and we don't want to rush that process. We'll take this on for the next foundational update where we will have some bake time.

+1 very annoying indeed. Every brace or semicolon in any method in @functions will break the whole document.

Moving this out from backlog to be addressed... Let's make sure we also have good tests for this area so this will never be a thing going forward.

please ensure that the fix covers the test cases in #2107

@NTaylorMullen, @danroth27 also has a repro, if you're interested

I was able to reproduce this but when I debugged this, it looks like our code (GetDesiredIndentation) isn't being called when it should be. Discussed with @NTaylorMullen. Looks like something changed with the editor formatting and the fix should go in there. Going to discuss with @ToddGrun and file an issue there.

Spoke to @ToddGrun and Bhavya. This is now being tracked here.

Closing as we track this separately.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

farhadibehnam picture farhadibehnam  路  3Comments

fayezmm picture fayezmm  路  3Comments

markrendle picture markrendle  路  3Comments

FourLeafClover picture FourLeafClover  路  3Comments

ipinak picture ipinak  路  3Comments