如何在vscode扩展中使用多个tmLanguage文件

时间:2019-05-27 17:46:54

标签: visual-studio-code vscode-extensions tmlanguage

我正在为 vscode 创建一个语言扩展。因为它将与不同的文件类型相关联,所以我计划针对特定规则制作不同的tmlanguge文件。根据{{​​3}},我可以扩展 mov ecx, 1 mov edi, ecx movss xmm0, dword ptr [rip + .LCPI0_0] call (output.test3(a: Swift.Int, b: Swift.Float) -> ()) 来实现。

因此,我在scopeName文件中创建了以下内容:

./package.json

然后,我在{ "name": "tst", "displayName": "Test Language", "description": "A test for language extension", "version": "0.0.1", "engines": { "vscode": "^1.34.0" }, "contributes": { "languages": [{ "id": "tst", "aliases": ["Test", "tst"], "extensions": [".tst",".type1",".type2"], "configuration": "./language-configuration.json" }], "grammars": [{ "language": "tst", "scopeName": "source.tst", "path": "./syntaxes/tst.tmLanguage.json" }, { "scopeName": "source.tst.type1", "path": "./syntaxes/type1.tmLanguage.json" }, { "scopeName": "source.tst.type2", "path": "./syntaxes/type2.tmLanguage.json" }] } } 中创建基本规则,并且./syntaxes/tst.tmLanguage.json.type1都已应用于我的语法。

.type2

然后,我也制作{ "name": "Test", "patterns": [ { "match": "test", "name": "constant.character" } ], "scopeName": "source.tst" } 像这样的东西:

./syntaxes/type1.tmLanguage.json

{ "name": "type1", "patterns": [ { "match": "type1", "name": "constant.language" } ], "scopeName": "source.tst.type1" } 中的任何规则都无效。

this

我希望图片中的两个文件都能识别 .type1 test 。 我检查了vscode预安装的cpp语言扩展。 他们还对type1source.c使用scopeName。 我想这是出于类似目的?

我忽略了什么吗? 感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

如果要在主语法中使用来自不同tmLanguage文件的这些作用域,则必须明确include它们:

{
    "name": "Test",
    "patterns": [
        {
            "match": "test",
            "name": "constant.character"
        },
        {
            "include": "source.tst.type1"
        },
        {
            "include": "source.tst.type2"
        }
    ],
    "scopeName": "source.tst"
}


关于内置的cpp扩展名和platform.tmLanguage.json-据我所知,c和cpp语法没有积极地使用它。 cpp/build/update-grammars.js中有此评论:

// `source.c.platform` which is still included by other grammars

这听起来更像是向后兼容的度量,以防任何第三方语法仍在使用它。