Visual Studio:基于正则表达式的自定义代码突出显示 [英] Visual Studio: Custom code highlighting based on regex

查看:116
本文介绍了Visual Studio:基于正则表达式的自定义代码突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的应用程序支持某种偏执的调试级别(每个数据分配,代码中的每一步都写入到日志目标位置),所以我的代码在某些方法(例如

)中会被日志调用打乱.

logger.Log(LogLevel.Debug, 0, "Initializing i18n...");
Lang.Language = SystemInfo.Language;
Logger.Log(LogLevel.Debug, 0, "Default system language: " + Lang.Language);
string[] languageFiles = Directory.GetFiles(ClientEnvironment.LanguagePath);
Logger.Log(LogLevel.Debug, 0, "Initializing local language files...");

如您所见,只有两条真实"代码行.这使得代码有些难以阅读.我想知道是否可以在Visual Studio中指定一些自定义代码格式规则,以使日志记录行以柔和的灰色文本颜色(而不是默认文本颜色)显示.这将导致真实"代码行的隐式突出显示,从而使代码更具可读性.

我需要类似的东西:

If statement starts with "logger.Log", set foreground color to gray.

您知道有哪些插件可以归档此类行为吗? 预先谢谢你.

解决方案

这不是发布者问题的适当答案,但是我不能删除它,因为StackOverflow不允许删除接受的答案.

此Visual Studio扩展将执行您想要的操作:

您可以为自定义输出窗口着色指定正则表达式.

As my application supports some paranoid debug level (every data assignment, every step in the code is written to a log destination), my code is littered with logging calls in some methods, e.g.

logger.Log(LogLevel.Debug, 0, "Initializing i18n...");
Lang.Language = SystemInfo.Language;
Logger.Log(LogLevel.Debug, 0, "Default system language: " + Lang.Language);
string[] languageFiles = Directory.GetFiles(ClientEnvironment.LanguagePath);
Logger.Log(LogLevel.Debug, 0, "Initializing local language files...");

As you can see, there are only two "real" code lines. This makes the code somewhat hard to read. I wonder whether I can specify some custom code formatting rule within Visual Studio to let the logging lines appear in a soft gray text color, instead of the default text color. This would lead to an implicit highlighting of the "real" code lines, resulting in a more readable code.

I need something like:

If statement starts with "logger.Log", set foreground color to gray.

Do you know any plugins which could archieve such a behaviour? Thank you in advance.

解决方案

Edit: This is not an appropriate answer to the poster's question, but I cannot delete it because StackOverflow won't allow the accepted answer to be deleted.

This Visual Studio extension will do just what you want:

You can specify regular expressions for custom output window colorization.

这篇关于Visual Studio:基于正则表达式的自定义代码突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆