From 3ffd0eddce651aabefedf10249ebd9d6e7b5b8fa Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 5 Feb 2023 16:43:59 +0200 Subject: [PATCH] Highlight more complex function parameters * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--fontify-parameter): New function. (rust-ts-mode--font-lock-settings): Use it. --- lisp/progmodes/rust-ts-mode.el | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el index 5722d037bba..e46fa0342dd 100644 --- a/lisp/progmodes/rust-ts-mode.el +++ b/lisp/progmodes/rust-ts-mode.el @@ -161,9 +161,7 @@ (macro_definition "macro_rules!" @font-lock-constant-face) (macro_definition (identifier) @font-lock-preprocessor-face) (field_declaration name: (field_identifier) @font-lock-property-face) - (parameter pattern: (identifier) @font-lock-variable-name-face) - (parameter - pattern: (reference_pattern (identifier) @font-lock-variable-name-face))) + (parameter) @rust-ts-mode--fontify-parameter) :language 'rust :feature 'function @@ -256,6 +254,18 @@ '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `rust-ts-mode'.") +(defalias 'rust-ts-mode--fontify-parameter + (and + (treesit-available-p) + `(lambda (node override start end &rest _) + (let ((captures (treesit-query-capture + (treesit-node-child-by-field-name node "pattern") + ,(treesit-query-compile 'rust '((identifier) @id))))) + (pcase-dolist (`(_name . ,id) captures) + (treesit-fontify-with-override + (treesit-node-start id) (treesit-node-end id) + 'font-lock-variable-name-face override start end)))))) + (defun rust-ts-mode--defun-name (node) "Return the defun name of NODE. Return nil if there is no name or if NODE is not a defun node." -- 2.39.5