queries: Inject markdown into Rust doc comments

Co-authored-by: Nik Revenco <154856872+nik-rev@users.noreply.github.com>
pull/12972/head
Michael Davis 2025-02-25 11:57:27 -05:00
parent a3b64b6da2
commit be1cf090c3
No known key found for this signature in database
5 changed files with 41 additions and 1 deletions

View File

@ -141,6 +141,7 @@
| make | ✓ | | ✓ | |
| markdoc | ✓ | | | `markdoc-ls` |
| markdown | ✓ | | | `marksman`, `markdown-oxide` |
| markdown-rustdoc | ✓ | | | |
| markdown.inline | ✓ | | | |
| matlab | ✓ | ✓ | ✓ | |
| mermaid | ✓ | | | |

View File

@ -1739,6 +1739,15 @@ block-comment-tokens = { start = "<!--", end = "-->" }
name = "markdown"
source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-markdown", rev = "62516e8c78380e3b51d5b55727995d2c511436d8", subpath = "tree-sitter-markdown" }
[[language]]
name = "markdown-rustdoc"
scope = "source.markdown-rustdoc"
grammar = "markdown"
injection-regex = "markdown-rustdoc"
file-types = []
indent = { tab-width = 2, unit = " " }
block-comment-tokens = { start = "<!--", end = "-->" }
[[language]]
name = "markdown.inline"
scope = "source.markdown.inline"

View File

@ -0,0 +1 @@
; inherits: markdown

View File

@ -0,0 +1,25 @@
; inherits: markdown
; In Rust, it is common to have documentation code blocks not specify the
; language, and it is assumed to be Rust if it is not specified.
(fenced_code_block
(code_fence_content) @injection.content
(#set! injection.language "rust")
(#set! injection.include-unnamed-children))
(fenced_code_block
(info_string
(language) @injection.language)
(code_fence_content) @injection.content (#set! injection.include-unnamed-children))
(fenced_code_block
(info_string
(language) @__language)
(code_fence_content) @injection.content
; list of attributes for Rust syntax highlighting:
; https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#attributes
(#match? @__language
"(ignore|should_panic|no_run|compile_fail|standalone_crate|custom|edition*)")
(#set! injection.language "rust")
(#set! injection.include-unnamed-children))

View File

@ -1,6 +1,10 @@
([(line_comment) (block_comment)] @injection.content
([(line_comment !doc) (block_comment !doc)] @injection.content
(#set! injection.language "comment"))
((doc_comment) @injection.content
(#set! injection.language "markdown-rustdoc")
(#set! injection.combined))
((macro_invocation
macro:
[