Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collapse all blocks of #ifdefs that will not be compiled in Visual Studio?

The problem is the following: the codebase have many files with multiple blocks compiled conditionally for each of target platforms using the #if defined(...) directive. Since the typical programmer is working mainly on one of the platforms it is quite hard to read and navigate the code with these large blocks of inactive code blocks even if the code blocks are greyed out in the Visual Studio 2005 editor.

Have someone have an idea of a functionality for collapsing only the blocks of code which are not compiled but still present in the source file.

like image 885
Singulus Avatar asked Jun 16 '10 12:06

Singulus


1 Answers

As far as I know, you cannot collapse inactive pre-processor regions by default and there doesn't seem to be an extension that provides the functionality.

That said, what you can do is change how inactive pre-processor text is rendered (at least on VS2012), so it is less distracting and so that the code that is actually compiled is easier to read.

Try these settings:

Tools > Options > Text Editor > C/C++ > Formatting:
Show Inactive Blocks : true
Disable Inactive Code Opacity : false
Inactive Code Opacity Percent: 30 

The default is 65, but I find 30 works better if you use the dark theme.

You can also further tweak the colours with the Visual Studio 2012 Color Theme Editor, to further increase readability (for example, if you prefer the way Sublime Text renders your code)

like image 85
Carl Avatar answered Sep 20 '22 16:09

Carl