如何在 VS Code 中更改区域/末端区域的颜色?

bak*_*nji 3 syntax customization visual-studio-code

有谁知道如何更改#region/#endregion 的颜色?这在 VS 社区中是灰色的,但在 VS Code 上不是。

先感谢您。

Mar*_*ark 5

因为术语 #region/#endregion 是注释的一部分,所以使用命令查看它们的范围Developer: Inspect TM Scopes只会给您一个comment范围,因此如果您通过以下 tokenColorCustomization 更改注释范围:

"editor.tokenColorCustomizations": {
    "comments": "#ffa600b0"
}
Run Code Online (Sandbox Code Playgroud)

将更改所有评论 - 可能不是您想要的。另外,您只能在那里更改 fontColor 和 fontStyle (如斜体)。

更好的是使用扩展程序Highlight通过正则表达式查找您想要突出显示的内容。

使用//#region- 您的语言在开始时可能有不同的注释指示符。如果是这样,请修改(//\\s*)下面的第一个捕获组。

  "highlight.regexes": {

    "(//\\s*)(#region|#endregion)": [

      // the first capture group, the '//' uncolored here, but must have the entry below
      //  you could color those separately if you wish
      {},

      // capture group: #region or #endregion
      {
        // "overviewRulerColor": "#ffcc00",
        "backgroundColor": "#f00",
        "color": "#fff",
        // "fontWeight": "bold",
        "borderRadius": "3px",
      },
    ]
  }
Run Code Online (Sandbox Code Playgroud)