覆盖 VS Code 中的默认语法着色

Override default syntax coloring in VS Code

我正在尝试覆盖 VS Code 中的默认语法着色。特别是默认主题 "Light (Visual Studio)" 中的 #a31515(红色)颜色,我想看到 #036A07(绿色)颜色。

为此,在 editor.tokenColorCustomizations 我的用户设置 settings.json 文件中,我更改了这个默认值:

"editor.tokenColorCustomizations": null

至:

"editor.tokenColorCustomizations": {
            "markup.deleted": "#036A07",
            "meta.preprocessor.string": "#036A07",
            "string": "#036A07",
            "entity.name.operator.custom-literal.string": "#036A07",
            "meta.embedded.assembly": "#036A07"
        }

我保存了 settings.json 文件并重新启动了 VS 代码,但我没有看到代码突出显示有任何变化(与之前相同的红色):




问题:我的代码有什么问题,正确的代码是什么?


根据下面@tHeSiD 的回答,我创建了这段代码并且它起作用了:

"editor.tokenColorCustomizations": {
      "textMateRules": [
        {
          "name": "Single Quotes",
          "scope": "string.quoted.single.python",
          "settings": {
          "fontStyle": "",
          "foreground": "#036A07"
          }
        }]
      }

仅针对特定主题设置:

"editor.tokenColorCustomizations": {
      "[Visual Studio Light]": {
        "textMateRules": [
          {
            "name": "Single Quotes",
            "scope": "string.quoted.single.python",
            "settings": {
            "fontStyle": "",
            "foreground": "#036A07"
            }
          }]
      }
  }

即使不将 editor.semanticHighlighting.enabled 设置为 false

也能正常工作

您必须像这样添加每个范围定义。

要获得所需的范围 - 使用命令面板 (CTRL SHIFT P) 然后 select Developer: Inspect Editor Tokens and Scopes

  "editor.tokenColorCustomizations": {
     "textMateRules": [
        {
          "name": "Deleted",
          "scope": "markup.deleted",
          "settings": {
            "fontStyle": "italic",
            "foreground": "#036A07"
          }
        },
        {
          "name": "Strings",
          "scope": "meta.preprocessor.string",
          "settings": {
            "fontStyle": "italic"
          }
        },
        {
          "name": "ThisIsJustANameForReference",
          //You can use coma separated scopes to group them into one
          "scope": "entity.name.operator.custom-literal.string, meta.embedded.assembly",
          "settings": {
            "foreground": "#036A07"
          }
        },
      ]
  },

这些是 textmate 规则,您必须禁用语义突出显示才能正常工作。为此添加 "editor.semanticHighlighting.enabled": false

如果你想通过语义高亮给所有东西上色,你必须使用这样的东西。

"semanticTokenColors": {
      "namespace": "#ffffff",
      "type": "#ffffff",
      "struct": "#ffffff",
      "class": "#ffffff",
      "class.readonly": {
         "foreground": "#ffffff",
         "fontStyle": "bold italic"
      },
      "*.declaration" : {
         "fontStyle": "bold"
      },
      "*.readonly" : "#ffffff",
  }