How to hide or collapse all javascript console.log lines in VSC

本小妞迷上赌 提交于 2021-02-05 09:24:09

问题


Lots of logging is very helpful to me.

However, sometimes I would like to temporarily reduce the clutter of code that I'm editing in VSC by hiding, collapsing, or reducing the opacity of the font of console.log, console.warn, and console.error lines in javascript, Vue, React, etc.

How could I accomplish my goal?

I'd love if there were some way to easily toggle the feature on/off.


回答1:


Thank you so much to @rioV8, who pointed me to the answer.

This seems to work for me when using extension Highlight:

"highlight.regexes": {
    "(console\\.(log|warn|error)\\(.+\\)[;]?)": {
        "regexFlags": "g",
        "decorations": [
          { "opacity": "0.1" }
        ]
      }
}

To determine what regular expression I wanted to use, I wrote these test cases in https://www.regexpal.com:

console.log('asdfdsf')
console.log({some})
console.log({some});
console.error('error', msg);
console.warn('careful', thing)

And (console\.(log|warn|error)\(.+\)[;]?) worked. Then I needed to add an extra \ before each \ to satisfy the VSC settings JSON file.

Now my VSC looks like this:



来源:https://stackoverflow.com/questions/65692310/how-to-hide-or-collapse-all-javascript-console-log-lines-in-vsc

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