Hide/fold/dim arbitrary lines of code by regex (e.g. to hide logging)

半世苍凉 提交于 2021-01-27 19:59:03

问题


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.

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.

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


回答1:


You can use extension Highlight.

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

Add to your settings.json

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

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" }
      ]
    }
  }


来源:https://stackoverflow.com/questions/65423970/hide-fold-dim-arbitrary-lines-of-code-by-regex-e-g-to-hide-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!