如何在vscode中正确插入语法扩展名(这样就可以了)?

时间:2019-02-20 12:56:09

标签: visual-studio-code grammar code-injection textmate

我很难扩展shell脚本语法,因为它仅突出显示bash-builtin命令。我想主要强调外壳命令,而不仅仅是内置命令。为此,我尝试通过注入来扩展语法,但这没有得到很好的记录,因此无论我在做什么,我都会一遍又一遍地遇到相同的问题。 如果我注入一些要被识别为功能的命令(并因此突出显示),它们就是这些命令,但是它们也会在注释中突出显示,这非常令人讨厌。无论我尝试哪种组合,我都不会摆脱它。由于support.function.extended.shell令牌由于注入而始终是最高值,因此它始终是彩色的。有什么解决办法吗?

如您在图片中所见,诸如“ echo”之类的内置命令在注释中没有变色

{
"scopeName": "shellcommand.injection",
"injectionSelector": "L:source.shell -support.function.builtin.shell",
"patterns": [{
    "include": "#shell-commands"
}],
"repository": {
    "shell-commands": {
        "patterns": [{

            "match": "(?<=^|;|&|\\s)(systemctl|cp|sed|awk)(?=\\s|;|&|$)",
            "name": "support.function.extended.shell"

        }]
    }
}

}

然后输出看起来像这样……

enter image description here

1 个答案:

答案 0 :(得分:2)

您可能需要一个更具体的进样选择器。尝试针对更具体的范围(不包含注释的范围)或从选择器中排除注释。我认为第二个示例将更适合您的示例。只需为此使用-否定选择器:

"injectionSelector": "L:source.shell -support.function.builtin.shell -comment"

enter image description here

相关问题