XML grammar: only the closing --> of a comment gets the scope comment.block.xml

オープン 初心者向け
#145 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

@alexeyfala がすでに取り組んでいます。

2026年12月5日 から。

  • #146 @alexeyfala による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp, json
領域
tooling

調査の方向性

src/TextMateSharp.Grammars/Resources/Grammars/xml/syntaxes/xml.tmLanguage.jsonから始め、特に352–392行付近の2つのコメントルールを確認し、リンク先のVS Code文法と比較します。どちらのコメント形式についても、ルールのスコープをcomment.block.xmlに、終了キャプチャのスコープをpunctuation.definition.comment.xmlに設定します。どちらの形式をトークン化しても、issueに示された期待どおりのスコープが得られれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

In the XML grammar of TextMateSharp.Grammars, the comment rules (<!-- --> and <%-- --%>) have no name; comment.block.xml is given only to the end capture:

https://github.com/danipen/TextMateSharp/blob/1176721ab747d6f2f78992f50111c0a04b942e72/src/TextMateSharp.Grammars/Resources/Grammars/xml/syntaxes/xml.tmLanguage.json#L352-L392

So the opening <!-- and the text of the comment get no comment scope, and a theme colors only the closing -->. In Light+ the comment text stays in the default foreground, and only --> is green. The XSL grammar includes text.xml, so it shows the same.

The grammar comes from atom/language-xml (per cgmanifest.json), where the <!-- rule has "name": "comment.block.xml" and marks both ends as punctuation; VS Code ships it that way:

https://github.com/microsoft/vscode/blob/10a1d2a50a2882f5ae85bdb51eb04d3064fb9de9/extensions/xml/syntaxes/xml.tmLanguage.json#L364-L383

The file has not changed since 2022-02-15, so 2.0.4, 2.0.5 and 3.0.0-preview.1 ship the same rules.

To Reproduce

RegistryOptions options = new(ThemeName.LightPlus);
IGrammar grammar = new Registry(options).LoadGrammar("text.xml");

foreach (IToken token in grammar.TokenizeLine("<!-- a comment -->").Tokens)
{
    Console.WriteLine(string.Join(" ", token.Scopes));
}

Output with TextMateSharp.Grammars 2.0.3:

[<!--] text.xml punctuation.definition.comment.xml
[ a comment ] text.xml
[-->] text.xml comment.block.xml

<%-- a comment --%> gives the same pattern.

Expected behavior

The whole comment has comment.block.xml, and both marks also have punctuation.definition.comment.xml:

[<!--] text.xml comment.block.xml punctuation.definition.comment.xml
[ a comment ] text.xml comment.block.xml
[-->] text.xml comment.block.xml punctuation.definition.comment.xml

Screenshots

None: the token scopes above show it.

Desktop (please complete the following information):

  • OS: Windows 11 Pro 10.0.26300 (the grammar is platform independent)
  • Version: TextMateSharp.Grammars 2.0.3; master has the same file

Additional context

This change of xml.tmLanguage.json gives the expected output above for both kinds of comments (checked by loading the changed file with LoadGrammarFromPathSync):

 					"end": "--%>",
 					"endCaptures": {
 						"0": {
-							"name": "comment.block.xml"
+							"name": "punctuation.definition.comment.xml"
 						}
-					}
+					},
+					"name": "comment.block.xml"
 				},
 					"end": "-->",
 					"endCaptures": {
 						"0": {
-							"name": "comment.block.xml"
+							"name": "punctuation.definition.comment.xml"
 						}
 					},
+					"name": "comment.block.xml",
 					"patterns": [

Until then we repair the raw grammar after reading it: for each rule of repository.comments whose end capture "0" is named comment.block.xml, we set that name on the rule (IRawRule.SetName) and rename the capture to punctuation.definition.comment.xml.

I can open a pull request with this change if that helps.

主要言語
C#
スター
170
フォーク
35
平均マージ
2時間 52分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

danipen/TextMateSharp のほかの issue

danipen/TextMateSharp の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。