如何为 VS Code 语言扩展的注释内的括号定义括号对着色?

问题描述 投票:0回答:1

我正在为一种语言制作 TextMate 语法以获得语法突出显示。这是文档评论中

@link
标签的规则:

"scopeName": "source.amx.pawn",
  "patterns": [
    {
      "name": "comment.block.documentation.amx.pawn",
      "begin": "/\\*\\*(?!/)",
      "end": "\\*/",
      "patterns": [{ "include": "#docblock" }]
    },
    // more patterns...
  ],
  "repository": {
    "docblock": {
      "patterns": [
        "match": "({)(@)(link|linkcode|linkplain)\\s+(\\w+)\\s+(.*)(})",
        "captures": {
          "1": { "name": "punctuation.definition.bracket.amx.pawn" },
          "2": { "name": "punctuation.docblock.at.amx.pawn" },
          "3": { "name": "storage.type.class.docblock.tag.amx.pawn" },
          "4": { "name": "variable.other.docblock.link.amx.pawn" },
          "5": { "name": "entity.name.type.instance.docblock.amx.pawn" },
          "6": { "name": "punctuation.definition.bracket.amx.pawn" },
        }
      ]
    },
    // more stuff...
  }
}

除了花括号之外,所有内容的颜色都正确。它们有标点符号颜色(这是我在规则中指定的)。

但我认为 vscode 无论如何都会在其上应用括号对着色器,例如,就像在打字稿上一样。

如您所见,在打字稿中它应用了括号对着色。

如果我检查编辑器标记和范围,这些是我的语法的大括号的文本范围:

punctuation.definition.bracket.amx.pawn
comment.block.documentation.amx.pawn
source.amx.pawn

这些是打字稿中大括号的范围:

punctuation.definition.bracket.curly.end.jsdoc
entity.name.type.instance.jsdoc
comment.block.documentation.ts
source.ts

唯一的区别是

entity.name.type.instance
范围,但我认为这是前一个标记的尾随范围,所以我猜测括号对着色器不关心这些范围。

如何才能达到与打字稿语法相同的结果?

visual-studio-code vscode-extensions syntax-highlighting grammar textmate
1个回答
0
投票

我遇到了同样的问题,并通过定义包含括号定义的语言配置来解决它。

// package.json
{
  "name": "langname",
  // other stuff ...
  "contributes": {
    "languages": [
      {
        "id": "langid",
        // other stuff...
        "configuration": "./language-configuration.json"
      }
    ],
    // other stuff ...
  }
}
// language-configuration.json
{
  "brackets": [
    ["{", "}"],
    ["[", "]"],
    ["(", ")"],
    // other tokens you want to colorize
  ],
  // other stuff...
}
© www.soinside.com 2019 - 2024. All rights reserved.