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

vas*_*111 2 visual-studio-code

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

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

"editor.tokenColorCustomizations": null
Run Code Online (Sandbox Code Playgroud)

到:

"editor.tokenColorCustomizations": {
            "markup.deleted": "#036A07",
            "meta.preprocessor.string": "#036A07",
            "string": "#036A07",
            "entity.name.operator.custom-literal.string": "#036A07",
            "meta.embedded.assembly": "#036A07"
        }
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述




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


从下面的 @tHeSiD 答案中,我创建了这段代码并且它有效:

"editor.tokenColorCustomizations": {
      "textMateRules": [
        {
          "name": "Single Quotes",
          "scope": "string.quoted.single.python",
          "settings": {
          "fontStyle": "",
          "foreground": "#036A07"
          }
        }]
      }
Run Code Online (Sandbox Code Playgroud)

仅针对特定主题进行设置:

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

它也无需设置即可editor.semanticHighlighting.enabled工作false

tHe*_*SiD 6

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

要获取所需的范围 - 使用命令选项板 (CTRL SHIFT P),然后选择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"
          }
        },
      ]
  },
Run Code Online (Sandbox Code Playgroud)

这些是文本伙伴规则,您必须禁用语义突出显示才能使其发挥作用。为此,请添加"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",
  }
Run Code Online (Sandbox Code Playgroud)