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

Aperta Adatta ai principianti
#145 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@alexeyfala ci sta già lavorando.

Dal 5/12/2026.

  • #146 di @alexeyfala — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, json
Ambito
tooling

Direzione di ricerca

Inizia da src/TextMateSharp.Grammars/Resources/Grammars/xml/syntaxes/xml.tmLanguage.json, in particolare dalle due regole dei commenti intorno alle righe 352–392, e confrontale con la grammatica di VS Code collegata. Imposta lo scope della regola su comment.block.xml e lo scope della cattura di chiusura su punctuation.definition.comment.xml per entrambe le forme di commento. Il lavoro è completato quando la tokenizzazione di entrambe le forme produce gli scope attesi mostrati nell’issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C#
Stelle
170
Fork
35
Merge medio
2h 52m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di danipen/TextMateSharp

Tutte le issue di danipen/TextMateSharp

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.