3

I started noticing that the indentation behavior of the C# #region and #endregion directives no longer get indented with my code.

Visual studio (2013) always pushes them to the first column of the line. This is not how it is supposed to work and it seems I have done something with my visual studio to make this happen (at work it behaves as it used to and regions get indented with the code).

I have ReSharper installed but can't seem to find anything in its settings either that may cause this and I don't know how to try to run without it.

What setting or bug this might be related to?

MC10
  • 552
  • 1
  • 12
  • 26
thehan83
  • 163
  • 1
  • 8
  • Might be worth noting that manually running the built-in "Format Selection" behaves correctly so what is broken here is the automatic formatting while typing. – thehan83 Apr 28 '15 at 07:30
  • Not sure if this is off topic or just opinion or whatever but I'll comment anyway. Please let me know if it's inappropriate I am new here. Do you really need region blocks? For navigating a code file then agreed, it works but there are easier ways.However, if your class is so vast that it needs IDE tricks to compact the code to be readable maybe it's time to divide it into separate classes that deal with individual responsibilities rather than sweeping it all under a region rug. I mention this with constructive intent and I know it's entirely subjective/religious/etc. (Two years region-free) – James Lucas Apr 28 '15 at 07:41
  • 1
    Yes it is kind of subjective and off topic. I know many people hate regions but I am not one of them. Furthermore I am working against a coding standard that calls for them for code structure (not to hide bad code or vast classes since my classes tend to be one responsibility only). – thehan83 Apr 28 '15 at 08:57
  • I noticed this and didn't look into this until now. It only happens to me if I select the autocomplete. If I actually type out `#region` or `#endregion` completely, it will auto-indent when I type the "n". I know it works in other versions of VS because I haven't changed my typing much. – DanCaveman Feb 25 '16 at 18:07

1 Answers1

4

Having a syntax error in your project in Visual Studio 2013 will cause the auto-indenting of regions to not work. Once you fix the error(s), regions should indent normally again.

MC10
  • 552
  • 1
  • 12
  • 26
  • Sharing *what* error in your code would be even more helpful. Even if the OP doesn't suffer the same error, it could lead to a similar or related one. – OhBeWise Jun 11 '15 at 20:55
  • It was just an error in general in Visual Studio. I'm guessing that having an error causes the auto-formatting of #region directives to fail. – MC10 Jun 11 '15 at 21:17
  • Interesting. Did you happen to try introducing other errors just to test that? That would be particularly intriguing - though I'd honestly have *no* idea why that would cause such a problem! Maybe someone else can enlighten us. – OhBeWise Jun 11 '15 at 21:41
  • 2
    I put a random line of meaningless text in my code to get an error. Then newly created regions would not get indented. I removed it and it would indent them. – MC10 Jun 11 '15 at 21:48
  • 1
    I believe it does answer the question. Auto-indenting of the #regions is a feature in Visual Studio. Just having an error in the current document you are working on will cause Visual Studio to stop doing this. When I say error, I mean any plain error in Visual Studio. Also, I just cleaned up my question a bit. I hope it's easier to understand now. – MC10 Jun 12 '15 at 14:05