From 81020267812e57a94982f2620241c1ad69a0fc1b Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Thu, 30 Nov 2023 00:13:10 +0100 Subject: [PATCH] rust-ts-mode: appropriately fontify doc strings Content-Type: text/plain; charset="utf-8" --- lisp/progmodes/rust-ts-mode.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el index 88344934e49..aef6b5cb91a 100644 --- a/lisp/progmodes/rust-ts-mode.el +++ b/lisp/progmodes/rust-ts-mode.el @@ -153,7 +153,7 @@ rust-ts-mode--font-lock-settings :language 'rust :feature 'comment - '(([(block_comment) (line_comment)]) @font-lock-comment-face) + '(([(block_comment) (line_comment)]) @rust-ts-mode--comment-docstring) :language 'rust :feature 'delimiter @@ -293,6 +293,16 @@ rust-ts-mode--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `rust-ts-mode'.") +(defun rust-ts-mode--comment-docstring (node override start end &rest _args) + "Use the comment or documentation face appropriately for comments." + (let* ((beg (treesit-node-start node)) + (end (treesit-node-end node)) + (prefix (buffer-substring-no-properties beg (min (+ beg 3) end))) + (face (if (string-equal "///" prefix) + 'font-lock-doc-face + 'font-lock-comment-face))) + (treesit-fontify-with-override beg end face override start end))) + (defun rust-ts-mode--fontify-scope (node override start end &optional tail-p) (let* ((case-fold-search nil) (face -- 2.42.0