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 condi开发者_开发知识库tionally 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.
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)
精彩评论