gpt4 book ai didi

visual-studio-code - 无法让范围检查员识别评论

转载 作者:行者123 更新时间:2023-12-04 09:36:07 27 4
gpt4 key购买 nike

我一直在尝试为我们在文档组合工具中使用的规则编写自己的语法高亮扩展。
我已经能够让大部分工作正常,但我无法让范围检查员识别评论。
我从 tmLanguage 文件中删除了所有其他工作代码以排除冲突,并留下以下内容
ote-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 扩展名),注释要么是带有双斜杠的行注释,要么是以 /* 开头和结尾的块注释。和 */分别
测试文本文件.txt
// just some comment text 
// indented comment
//
// left the above line empty apart from slashes
/*
inline block comment
*/
当我使用范围检查器查看上面的文本时,它正在重新识别它来自 source.ote-rules 但将 token 类型显示为“其他”
screenshot of scope inspector output showing scope as 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"
}
]
}

关于visual-studio-code - 无法让范围检查员识别评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62579709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com