我有一些关于 VSCode Syntax Highlighting tmLanguage.json 的问题,到目前为止,我在浏览 google 和 VSCode 文档(和 textmate 文档)时无法轻松找到这些问题。所有这些都适用于构建您自己的语言扩展(我曾经yo code
生成项目)。其中大多数是关于我的特定用例的。
- 您如何指定用户可以覆盖的自定义设置?我想将自动换行指定为我的脚本的可切换选项。
- 你如何选择一些范围,所以颜色是你想要的?
- 如何正确设置括号的样式?
这就是我所拥有的。
样式是:
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "MyScript",
"patterns": [
{
"include": "#terms"
},
{
"include": "#punctuations"
},
{
"include": "#strings"
},
{
"include": "#numbers"
}
],
"repository": {
"terms": {
"patterns": [
{
"name": "entity.name.type.language.myscript",
"match": "([a-z][a-z0-9]*(?:-[a-z0-9]+)*)"
},
{
"name": "entity.name.type.language.parens.myscript",
"begin": "([a-z][a-z0-9]*(?:-[a-z0-9]+)*)\\(",
"end": "\\)",
"patterns": [
{
"includes": "#terms"
},
{
"includes": "#strings"
},
{
"includes": "#numbers"
}
]
}
]
},
"numbers": {
"patterns": [
{
"name": "constant.numeric.integer.myscript",
"match": "\\b(\\d+)\\b"
},
{
"name": "constant.numeric.decimal.myscript",
"match": "\\b(\\d+\\.\\d+)\\b"
}
]
},
"punctuations": {
"patterns": [
{
"name": "punctuation.separator.parameter.myscript",
"match": ","
},
{
"name": "punctuation.curly.open.myscript",
"match": "\\{"
},
{
"name": "punctuation.curly.close.myscript",
"match": "\\}"
}
]
},
"strings": {
"name": "string.myscript",
"begin": "\\<",
"end": "\\>",
"patterns": [
{
"name": "constant.character.escape.myscript",
"match": "\\\\."
},
{
"name": "punctuation.term.myscript",
"begin": "\\{",
"beginCaptures": {
"0": {
"name": "meta.brace.curly.myscript"
}
},
"end": "\\}",
"endCaptures": {
"0": {
"name": "meta.brace.curly.myscript"
}
},
"patterns": [
{
"include": "#terms"
},
{
"include": "#numbers"
},
{
"include": "#strings"
}
]
}
]
}
},
"scopeName": "source.myscript"
}
entity.name.type
给定我的默认 GitHub 主题,我通过选择 获得了绿松石色。我不希望自定义主题,我只是希望它映射到主题中的一组给定颜色。我想:
- 黑色的“实体”(条款)
- 蓝色代表“字符串”
- “数字”为绿色
- 标点符号为灰色
我一直在修补一段时间,试图让<text {term}>
花括号不为红色,但我无法弄清楚。周围的括号another(123)
也应该是灰色的。
我不知道其他语言是如何定义它们的样式的,比如 JSON(我想要的蓝色):
或其他 JSON:
红色的逗号也应该是灰色的。