我正在尝试为Ribosome .py.dna
个文件创建VSCode扩展程序
基本上,.py.dna
与python相同,只是以.
开头的行应该有注释语法突出显示。
到目前为止,这就是我对tmLanguage.json
:
{
"name": "RibosomePython",
"patterns": [
{
"include": "#dots"
}
],
"repository": {
"dots": {
"name": "comment.dna",
"begin": "\\.",
"end": "$"
}
},
"scopeName": "source.python.dna"
}
这是有效的,因为以.
开头的行有python注释语法高亮显示。但是现在我不确定如何告诉VSCode让真正的Python语法突出其他所有内容。我怎么能这样做?
我的package.json
看起来像是:
{
"name": "ribosome-dna",
"displayName": "Ribosome DNA",
"description": "Ribosome DNA Syntax Highlighting",
"version": "0.0.1",
"publisher": "rpgillespie",
"engines": {
"vscode": "^1.17.0"
},
"categories": [
"Languages"
],
"contributes": {
"languages": [{
"id": "dna",
"aliases": ["DNA"],
"extensions": [".py.dna"],
"configuration": "./language-configuration.json"
}],
"grammars": [
{
"language": "dna",
"scopeName": "source.python.dna",
"path": "./syntaxes/dna.tmLanguage.json"
}
]
}
}
注意我能够通过复制和修改python的语法让它以我想要的方式工作,但这看起来有些过分。
编辑:
对于已发布的好奇,已完成的扩展here。
答案 0 :(得分:1)
只需将"include": "source.python"
添加到patterns
:
{
"name": "RibosomePython",
"patterns": [
{
"include": "#dots"
},
{
"include": "source.python"
}
],
"repository": {
"dots": {
"name": "comment.dna",
"begin": "\\.",
"end": "$"
}
},
"scopeName": "source.python.dna"
}
此功能称为injection grammar。 VSCode在响应#2793时添加了对此的支持。