Skip to content

Commit 8ad70e7

Browse files
committed
Auto merge of rust-lang#14866 - AndreasBackx:feature/doc-comments-markdown, r=Veykril
[editors/code] add markdown syntax highlighting to doc comments _This is a continuation of microsoft/vscode#169956 and dustypomerleau/rust-syntax#37 (that repo is no longer maintained: dustypomerleau/rust-syntax#39 (comment)). The VS Code team seemed to prefer this being inside of an extension._ This adds Markdown highlighting to doc comment lines and blocks. Currently it is thus regarded both as a comment and as Markdown which leads to normally foreground text being in the colour of the comment and the rest highlighted like Markdown or its own embedded languages in code blocks. ![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/c84f2e83-faea-47ca-853d-3728a07b2b66) ![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/f4191425-32cd-451c-ae3a-29a0970ce7a2) Block comments are supported, but currently not when there is a `*` at the start of the line: ![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/ce3b58d5-9dca-4376-bffe-4f5a54acbe37) ![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/b73a5ee6-a178-4aef-a0e4-3d75e4e7d8e5) I'm not entirely sure if I can easily fix this, I'd need to find a way to make the content ignore the `*`. Though I'm unsure if it's important as there are [conventions against using block comments]( https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#use-line-comments) and using them without `*` does work. All of this TextMate grammar is so hard to find documentation on that _honestly_ I'd just not want to support this considering the effort. Let me know what everyone thinks of this being in rust-analyzer. I've personally found it hard to write large amounts of Rust documentation due to the lack of Markdown syntax highlighting. Also, thank you `@adenine-dev` as well for making this available in the interim and your enthousiasm. Wanted to get this PR out sooner, but life gets in the way.
2 parents 2df56ca + 09f6247 commit 8ad70e7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,16 @@
15621562
"language": "ra_syntax_tree",
15631563
"scopeName": "source.ra_syntax_tree",
15641564
"path": "ra_syntax_tree.tmGrammar.json"
1565+
},
1566+
{
1567+
"scopeName": "rustdoc.markdown.injection",
1568+
"path": "rustdoc.markdown.injection.tmGrammar.json",
1569+
"injectTo": [
1570+
"source.rust"
1571+
],
1572+
"embeddedLanguages": {
1573+
"meta.embedded.block.markdown": "text.html.markdown"
1574+
}
15651575
}
15661576
],
15671577
"problemMatchers": [
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"scopeName": "rustdoc.markdown.injection",
3+
"injectionSelector": "L:source.rust",
4+
"patterns": [
5+
{
6+
"include": "#doc-comment-line"
7+
},
8+
{
9+
"include": "#doc-comment-block"
10+
}
11+
],
12+
"repository": {
13+
"doc-comment-line": {
14+
"name": "comment.line.documentation.rust",
15+
"begin": "^\\s*//(/|!)",
16+
"while": "^\\s*//(/|!)",
17+
"contentName": "meta.embedded.block.markdown",
18+
"patterns": [
19+
{
20+
"include": "text.html.markdown"
21+
}
22+
]
23+
},
24+
"doc-comment-block": {
25+
"name": "comment.block.documentation.rust",
26+
"begin": "/\\*(\\*|!)",
27+
"end": "\\s*\\*/",
28+
"contentName": "meta.embedded.block.markdown",
29+
"patterns": [
30+
{
31+
"include": "text.html.markdown"
32+
}
33+
]
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)