代码之家  ›  专栏  ›  技术社区  ›  Sonny D

如何从自定义语言为某些标记着色?

  •  0
  • Sonny D  · 技术社区  · 7 年前

    我创建自定义语言 abc ,来自教程 https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide ,因此我的文件包含:

    {
        "contributes": {
            "languages": [
                {
                    "id": "abc",
                    "extensions": [".abc"]
                }
            ],
            "grammars": [
                {
                    "language": "abc",
                    "scopeName": "source.abc",
                    "path": "./syntaxes/abc.tmGrammar.json"
                }
            ]
        }
    }
    

    abc.tmGrammar.json:

    {
        "scopeName": "source.abc",
        "patterns": [{ "include": "#expression" }],
        "repository": {
            "expression": {
                "patterns": [{ "include": "#letter" }, { "include": "#paren-expression" }]
            },
            "letter": {
                "match": "a|b|c",
                "name": "keyword.letter"
            },
            "paren-expression": {
                "begin": "\\(",
                "end": "\\)",
                "beginCaptures": {
                    "0": { "name": "punctuation.paren.open" }
                },
                "endCaptures": {
                    "0": { "name": "punctuation.paren.close" }
                },
                "name": "expression.group",
                "patterns": [{ "include": "#expression" }]
            }
        }
    }
    

    这是可行的,因为当我打开VSC时,我可以看到并拾取 abc 语言现在如何上色 expression.group 到#ff0000的代币?在哪里为它定义颜色?在里面 package.json colors 贡献点?

    0 回复  |  直到 7 年前
        1
  •  0
  •   sheilaCat    6 年前

    您只能设置自己的主题样式,或在“用户设置”中设置颜色。

    https://github.com/microsoft/vscode/issues/66729

    您可以在命令中看到范围 developer inspect editor tokens and scopes

    
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            // JavaScript
            {
                "scope": "source.js keyword",
                "settings": {
                    "foreground": "#FF0000"
                }
            },
            // TypeScript
            {
                "scope": "source.ts keyword",
                "settings": {
                    "foreground": "#0000ff"
                }
            },
        ]
    }