Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect Lambda Expression Indentation

I've been having this problem for awhile in Visual Studio 2013. It doesn't seem to understand how to apply the indentation rules properly to lambda expressions when they've been lined up incorrectly. Here is a simplified example:

var s = new Action(() =>
   {
   });

In the second and third row, the indent is only 3 spaces instead of 4 (the real code example is much, much larger with the inner expression spanning hundreds of lines - this was checked in by my colleague and I'm trying to fix it). I've tried every combination of reformat code, document, re-creating the curly brace, etc. Nothing seems to work. It refuses to automatically update the indentation properly.

I normally wouldn't bother with it, but it causes all the code inside to be off by 1 character as well. When I'm typing lines in the middle, the tab/shift+tab markers are 1 character off from the lines above and below and I constantly have to adjust to get things lined up again. The closest thing I can find to reference this issue is this Connect Feedback from 2013 that is supposedly fixed, but I'm on Update 4 (released Nov 2014) and still experiencing the issue.

Short of manually going through and updating the indentation for every line in the lambda expression, does anyone have an idea how I can quickly fix this code?

like image 286
mellamokb Avatar asked Dec 09 '14 00:12

mellamokb


1 Answers

Blatantly ignoring the issue in Visual Studio, and providing a solution to the problem right away. Hold alt to enable block selection, select all lines, and type a single space. Just to illustrate:

Block Selection

If you type Hello World!, the result would be:

After Typing

As a 'rant': a single lambda should not contain hundreds of lines of code, it is a very big nono maintainability wise.

like image 86
Bas Avatar answered Oct 20 '22 10:10

Bas