XML grammar: only the closing --> of a comment gets the scope comment.block.xml
评估
调研方向
从 src/TextMateSharp.Grammars/Resources/Grammars/xml/syntaxes/xml.tmLanguage.json 开始,重点查看第 352–392 行附近的两条注释规则,并将它们与链接的 VS Code grammar 进行比较。对于两种注释形式,都将规则 scope 设为 comment.block.xml,并将结束捕获 scope 设为 punctuation.definition.comment.xml。完成标准是:对任一种形式进行 tokenizing 后,都能得到 issue 中展示的预期 scopes。
由索引模型根据 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:
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:
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 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danipen/TextMateSharp 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
danipen/TextMateSharp#123 · 3 条评论 ·
-
难度 3/5 1-2 天 新手友好度 44/100
danipen/TextMateSharp#120 · 38 条评论 · 1 个 reaction ·
-
good first issue
难度 4/5 3-5 天 新手友好度 35/100
danipen/TextMateSharp#119 ·
-
难度 4/5 3-5 天 新手友好度 35/100
danipen/TextMateSharp#118 · 11 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
danipen/TextMateSharp#75 · 2 条评论 ·
查看 danipen/TextMateSharp 的全部 Issue
相似的 Issue
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 85/100
Klyroo/klyroo-dashboard#12 ·
维护者通常 1 天内回复
-
CONTRIBUTING rules Node out in step 0, then tells client-side contributors to run node --test, which is what CI gates on可能已有人在做 @yadavraj2001 今天认领。 未关闭documentation good first issue
难度 1/5 1-3 小时 新手友好度 82/100
juandresrodca/AdminForge#73 · 1 条评论 ·
维护者通常 1 天内回复
-
[辞書] VIVANT未关闭要トリアージ 辞書
难度 1/5 1 小时以内 新手友好度 70/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 1/5 1 小时以内 新手友好度 94/100
christian-raj/S-Aloha#504 ·
-
Issue: Feature Request Xenonid
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复