通过正则表达式隐藏/折叠/变暗任意代码行(例如隐藏日志记录) [英] Hide/fold/dim arbitrary lines of code by regex (e.g. to hide logging)

查看:35
本文介绍了通过正则表达式隐藏/折叠/变暗任意代码行(例如隐藏日志记录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 C++ 项目中有很多日志记录.日志记录是通过日志流完成的,日志行具有以下格式:

There is a lot of logging in my C++ project. The logging is done via a log stream and the log lines have the following format:

APP_LOG_XXX() << ... ;

那些日志行与代码的其余部分混合在一起,使其更难阅读.

Those log lines blend with the rest of the code and make it harder to be read.

我想以某种方式使这些日志行以暗色显示,或者更好地通过热键或单击隐藏/折叠.已经有很多日志行,因此将它们包装在 #pragma region 中会花费很多时间(或者需要编写单独的脚本).不知道有没有更简单的方法.

I want to somehow make these log lines appear in dimmed colors, or even better to hide/fold by a hotkey or click. There are a lot of log lines already, so wrapping them up in #pragma region would take much time (or would require writing a separate script). I wonder if there is an easier way.

(有一个非常关于 SO 的类似问题,但它是关于 Visual Studio,而不是 Visual Studio Code).

(There is a very similar question on SO, but it's about Visual Studio, not Visual Studio Code).

推荐答案

您可以使用扩展 突出显示.

将颜色设置为与您的主题背景颜色接近的版本

Set the color to a version close to your theme background color

添加到您的 settings.json

  "highlight.regexes": {
    "(APP_LOG_XXX\\(\\) <<[^;]+;)": {
      "regexFlags": "mg",
      "decorations": [
        { "color": "#f0f0f0" }
      ]
    }
  }

或者你可以使用 opacity 装饰属性代替.以下配置将在保留其当前语法突出显示的同时使文本变暗:

Or you can use the opacity decoration property instead. The following configuration will dim the text while preserving its current syntax highlighting:

  "highlight.regexes": {
    "(APP_LOG_XXX\\(\\) <<[^;]+;)": {
      "regexFlags": "mg",
      "decorations": [
        { "opacity": "0.4" }
      ]
    }
  }

这篇关于通过正则表达式隐藏/折叠/变暗任意代码行(例如隐藏日志记录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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