From d8e094e68fcaf3bacd032dee1ed548f0971ac505 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 14 Mar 2025 21:20:06 +0000 Subject: [PATCH 1/5] feat: inject `rust` language into markdown code blocks in Rust documentation comments --- languages.toml | 11 +++++++++++ runtime/queries/markdown-rustdoc/highlights.scm | 1 + runtime/queries/markdown-rustdoc/injections.scm | 15 +++++++++++++++ runtime/queries/rust/injections.scm | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/markdown-rustdoc/highlights.scm create mode 100644 runtime/queries/markdown-rustdoc/injections.scm diff --git a/languages.toml b/languages.toml index 3e790d76e3eb..5c42078b745c 100644 --- a/languages.toml +++ b/languages.toml @@ -1704,6 +1704,17 @@ block-comment-tokens = { start = "" } 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 = [] +roots = [] +language-servers = [] +indent = { tab-width = 2, unit = " " } +block-comment-tokens = { start = "" } + [[language]] name = "markdown.inline" scope = "source.markdown.inline" diff --git a/runtime/queries/markdown-rustdoc/highlights.scm b/runtime/queries/markdown-rustdoc/highlights.scm new file mode 100644 index 000000000000..a3a30e342921 --- /dev/null +++ b/runtime/queries/markdown-rustdoc/highlights.scm @@ -0,0 +1 @@ +; inherits: markdown diff --git a/runtime/queries/markdown-rustdoc/injections.scm b/runtime/queries/markdown-rustdoc/injections.scm new file mode 100644 index 000000000000..8beba4e237b6 --- /dev/null +++ b/runtime/queries/markdown-rustdoc/injections.scm @@ -0,0 +1,15 @@ +; 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)) + diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index e4ae6ab352c1..42ca12b5b8ab 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -2,7 +2,7 @@ (#set! injection.language "comment")) ((doc_comment) @injection.content - (#set! injection.language "markdown") + (#set! injection.language "markdown-rustdoc") (#set! injection.combined)) ((macro_invocation From 753c72cdf6f9f599ca2ed0fcc68c485077c913b6 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 14 Mar 2025 21:24:13 +0000 Subject: [PATCH 2/5] docs: add information on markdown-rustdoc --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 0d4bc7f8f627..07823b28eeef 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -138,6 +138,7 @@ | make | ✓ | | ✓ | | | markdoc | ✓ | | | `markdoc-ls` | | markdown | ✓ | | | `marksman`, `markdown-oxide` | +| markdown-rustdoc | ✓ | | | | | markdown.inline | ✓ | | | | | matlab | ✓ | ✓ | ✓ | | | mermaid | ✓ | | | | From 06f941179acb6da18d5c4e09e2d41557adfe9d07 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+nik-rev@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:17:54 +0000 Subject: [PATCH 3/5] feat: add support for embedded cargo manifest --- runtime/queries/markdown-rustdoc/injections.scm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/queries/markdown-rustdoc/injections.scm b/runtime/queries/markdown-rustdoc/injections.scm index 8beba4e237b6..958f5d16f476 100644 --- a/runtime/queries/markdown-rustdoc/injections.scm +++ b/runtime/queries/markdown-rustdoc/injections.scm @@ -8,6 +8,13 @@ (#set! injection.language "rust") (#set! injection.include-unnamed-children)) +; cargo-script uses an embedded virtual Cargo manifest +(fenced_code_block + (info_string + (language) @_language) + (code_fence_content) @injection.content +(#eq? @_language "cargo") (#set! injection.language "toml") (#set! injection.include-unnamed-children)) + (fenced_code_block (info_string (language) @injection.language) From a63955709367eb222c291ac5f5e2bbf8e57976ca Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+nik-rev@users.noreply.github.com> Date: Sat, 15 Mar 2025 17:15:39 +0000 Subject: [PATCH 4/5] revert: remove cargo virtual manifest --- runtime/queries/markdown-rustdoc/injections.scm | 7 ------- 1 file changed, 7 deletions(-) diff --git a/runtime/queries/markdown-rustdoc/injections.scm b/runtime/queries/markdown-rustdoc/injections.scm index 958f5d16f476..8beba4e237b6 100644 --- a/runtime/queries/markdown-rustdoc/injections.scm +++ b/runtime/queries/markdown-rustdoc/injections.scm @@ -8,13 +8,6 @@ (#set! injection.language "rust") (#set! injection.include-unnamed-children)) -; cargo-script uses an embedded virtual Cargo manifest -(fenced_code_block - (info_string - (language) @_language) - (code_fence_content) @injection.content -(#eq? @_language "cargo") (#set! injection.language "toml") (#set! injection.include-unnamed-children)) - (fenced_code_block (info_string (language) @injection.language) From 5d26d394c054526cab6c1dba84a67ac3426a036a Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 15 Mar 2025 14:27:26 -0500 Subject: [PATCH 5/5] Update languages.toml --- languages.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/languages.toml b/languages.toml index 5c42078b745c..3652e17af45e 100644 --- a/languages.toml +++ b/languages.toml @@ -1710,8 +1710,6 @@ scope = "source.markdown-rustdoc" grammar = "markdown" injection-regex = "markdown-rustdoc" file-types = [] -roots = [] -language-servers = [] indent = { tab-width = 2, unit = " " } block-comment-tokens = { start = "" }