无法让范围检查员识别评论
Can't get the scope inspector to recognise comments
我一直在尝试为我们在文档撰写工具中使用的规则编写自己的语法突出显示扩展。
我已经能够让它的大部分工作正常,但我就是无法让范围检查员识别评论。
我从 tmLanguage 文件中删除了所有其他工作代码以排除冲突并留下以下内容
注意-rules.tmLanguage.json
{
"scopeName": "source.ote-rules",
"patterns": [{
"include": "#expression"
}],
"repository": {
"expression": {
"patterns": [
{
"include": "#comments-ote"
}
]
},
"comments-ote": {
"patterns": [{
"include": "#comments-block"
},
{
"include": "#comments-line"
}
],
"comments-line": {
"match": "\/\/.*?$",
"name": "comment.line.double-slash.ote-rules"
},
"comments-block": {
"begin": "\/\*",
"end": "\*\/",
"beginCaptures":{
"0":{"name":"punctuation.definition.comment.ote-rules"}
},
"endCaptures":{
"0":{"name":"punctuation.definition.comment.ote-rules"}
}
}
}
}
}
我要匹配的文件是纯文本文件(*.txt
扩展名),注释是带有双正斜杠的行注释或以 [=13= 开头和结尾的块注释]和*/
分别
测试文字file.txt
// just some comment text
// indented comment
//
// left the above line empty apart from slashes
/*
inline block comment
*/
当我用范围检查器查看上面的文本时,它正在识别它来自 source.ote-rules 但将令牌类型显示为 'other'
我已经检查了 rubular.com 上的正则表达式,它们似乎适用于我展示的示例,所以我错过了什么?
问题是 #
引用中包含的模式必须直接在 "repository"
中,但您将它们嵌套到 "comments-ote"
中。它根本找不到它们。
此外,您可能想给 "comments-block"
一个作用域名称,以便将其突出显示为注释,例如 "name": "comment.block.ote-rules"
.
{
"scopeName": "source.ote-rules",
"patterns": [
{
"include": "#expression"
}
],
"repository": {
"expression": {
"patterns": [
{
"include": "#comments-ote"
}
]
},
"comments-ote": {
"patterns": [
{
"include": "#comments-block"
},
{
"include": "#comments-line"
}
]
},
"comments-line": {
"match": "\/\/.*?$",
"name": "comment.line.double-slash.ote-rules"
},
"comments-block": {
"begin": "\/\*",
"end": "\*\/",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"name": "comment.block.ote-rules"
}
}
}
注意:不需要使用"include"
,也可以直接在"patterns"
中指定模式:
"comments-ote": {
"patterns": [
{
"match": "\/\/.*?$",
"name": "comment.line.double-slash.ote-rules"
},
{
"begin": "\/\*",
"end": "\*\/",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"name": "comment.block.ote-rules"
}
]
}
我一直在尝试为我们在文档撰写工具中使用的规则编写自己的语法突出显示扩展。
我已经能够让它的大部分工作正常,但我就是无法让范围检查员识别评论。
我从 tmLanguage 文件中删除了所有其他工作代码以排除冲突并留下以下内容
注意-rules.tmLanguage.json
{
"scopeName": "source.ote-rules",
"patterns": [{
"include": "#expression"
}],
"repository": {
"expression": {
"patterns": [
{
"include": "#comments-ote"
}
]
},
"comments-ote": {
"patterns": [{
"include": "#comments-block"
},
{
"include": "#comments-line"
}
],
"comments-line": {
"match": "\/\/.*?$",
"name": "comment.line.double-slash.ote-rules"
},
"comments-block": {
"begin": "\/\*",
"end": "\*\/",
"beginCaptures":{
"0":{"name":"punctuation.definition.comment.ote-rules"}
},
"endCaptures":{
"0":{"name":"punctuation.definition.comment.ote-rules"}
}
}
}
}
}
我要匹配的文件是纯文本文件(*.txt
扩展名),注释是带有双正斜杠的行注释或以 [=13= 开头和结尾的块注释]和*/
分别
测试文字file.txt
// just some comment text
// indented comment
//
// left the above line empty apart from slashes
/*
inline block comment
*/
当我用范围检查器查看上面的文本时,它正在识别它来自 source.ote-rules 但将令牌类型显示为 'other'
我已经检查了 rubular.com 上的正则表达式,它们似乎适用于我展示的示例,所以我错过了什么?
问题是 #
引用中包含的模式必须直接在 "repository"
中,但您将它们嵌套到 "comments-ote"
中。它根本找不到它们。
此外,您可能想给 "comments-block"
一个作用域名称,以便将其突出显示为注释,例如 "name": "comment.block.ote-rules"
.
{
"scopeName": "source.ote-rules",
"patterns": [
{
"include": "#expression"
}
],
"repository": {
"expression": {
"patterns": [
{
"include": "#comments-ote"
}
]
},
"comments-ote": {
"patterns": [
{
"include": "#comments-block"
},
{
"include": "#comments-line"
}
]
},
"comments-line": {
"match": "\/\/.*?$",
"name": "comment.line.double-slash.ote-rules"
},
"comments-block": {
"begin": "\/\*",
"end": "\*\/",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"name": "comment.block.ote-rules"
}
}
}
注意:不需要使用"include"
,也可以直接在"patterns"
中指定模式:
"comments-ote": {
"patterns": [
{
"match": "\/\/.*?$",
"name": "comment.line.double-slash.ote-rules"
},
{
"begin": "\/\*",
"end": "\*\/",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.ote-rules"
}
},
"name": "comment.block.ote-rules"
}
]
}