VS 代码扩展:如何匹配 "strings" 而不覆盖另一个模式的颜色 (tmLanguage.json)

VS Code Extension: how to match "strings" without overwrite the color of another pattern (tmLanguage.json)

我正在为 Visual Studio 代码编写特定语言的扩展,到目前为止,我可以为多个命令设置颜色。

我的 mylang.tmLanguage.json 包含(简化)以下内容:

{
    "\$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
    "name": "F-Script",
    "patterns": [
        { 
            "include": "#goto"      
        },       
        {
            "include": "#strings"
        }
    ],
    "repository": {
        "GOTO": 
        {
            "patterns": 
            [{
                "name": "support.function",
                "match": "/(?!«)[a-zA-Z0-9_.\-«»/(/)]{1,}(?=»)\b"
            },
            {
                "name": "support.function",
                "match":"GOTO[(]{1}(# [a-zA-Z0-9_.-]{1,}|/)[)]{1}"
            }]
        },
        "strings": {
            "name": "string.quoted.double.f-script",
            "begin": "\"|\'",
            "end": "\"|\'",
            "patterns": [
                {
                    "name": "constant.character.escape.f-script",
                    "match": "$"
                }
            ]
        }                                       
    },
    "scopeName": "source.f-script"
}

当我尝试测试 "strings" 的颜色时,否决了命令 GOTO。

«GOTO(# THIS.COLOR.GOTO)»
"This Should be formated like a String"
"This Should be formated like a String «GOTO(# THIS.COLOR.GOTO)»"

我尝试做的是第 3 行的 GOTO 颜色与第一个转到相同。我的问题是整行颜色像字符串(包括 GOTO 命令)。

有谁知道我如何设置字符串格式为字符串并且包含的​​命令颜色不同?

您可以简单地将 goto 包含在 strings 的模式中:

"strings": {
    "name": "string.quoted.double.f-script",
    "begin": "\"|\'",
    "end": "\"|\'",
    "patterns": [
        {
            "name": "constant.character.escape.f-script",
            "match": "$"
        },
        {
            "include": "#goto"
        }
    ]
}