如何折叠所有不会在 Visual Studio 中编译的 #ifdefs 块?

发布于 2024-09-05 12:20:45 字数 188 浏览 6 评论 0原文

问题如下:代码库有许多文件,其中包含使用 #if Defined(...) 指令为每个目标平台有条件编译的多个块。由于典型的程序员主要在其中一种平台上工作,因此即使这些代码块在 Visual Studio 2005 编辑器中呈灰色显示,也很难通过这些大块非活动代码块来读取和导航代码。

让某人了解一种仅折叠未编译但仍存在于源文件中的代码块的功能。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一紙繁鸢 2024-09-12 12:20:45

据我所知,默认情况下不能折叠不活动的预处理器区域,并且似乎没有提供该功能的扩展。

也就是说,您可以做的是更改非活动预处理器文本的呈现方式(至少在 VS2012 上),这样就不会那么分散注意力,并且实际编译的代码更容易阅读。

尝试这些设置:

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

默认值为 65,但我发现如果您使用深色主题,则 30 效果更好。

您还可以使用 Visual Studio 2012 颜色主题编辑器,进一步提高可读性(例如,如果您更喜欢 Sublime Text 呈现代码的方式)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文