queries: Inject markdown into Rust doc comments

Co-authored-by: Nik Revenco <154856872+nik-rev@users.noreply.github.com>
This commit is contained in:
Michael Davis 2025-02-25 11:57:27 -05:00
parent ac88096c98
commit 813f771c0a
No known key found for this signature in database
5 changed files with 30 additions and 1 deletions

View file

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

View file

@ -1704,6 +1704,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,14 @@
; 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))

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:
[