Subject: Re: bug#74277: 29.4; rust-ts-mode doesn't highlight some function calls

From: Trevor Arjeski <[email-masked]>
Date: Wed, 20 Nov 2024 21:22:28 +0300

Trevor Arjeski <[email-masked]> writes:

I decided to hack around with this a little bit and found that adding
the following lines partially works:

diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index e52ea3b125a..508a53d9e32 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -517,6 +517,19 @@ rust-ts-mode
     (setq-local syntax-propertize-function
                 #'rust-ts-mode--syntax-propertize)
 
+    ;; Injected languages
+    ;; TODO: add json?
+    (setq-local treesit-range-settings
+                (treesit-range-rules
+                 :embed 'rust
+                 :host 'rust
+                 :local t
+                 '((macro_invocation
+                    (token_tree) @capture))))
+
+    ;; TODO: set this to a useful function
+    (setq-local treesit-language-at-point-function (lambda (_pos) 'rust))
+
     ;; Comments.
     (c-ts-common-comment-setup)

I'm sure there is an issue with solving it this way, I just need someone
else more experienced to confirm. It is finicky where it turns the
highlighting on and off when you make some code changes, for example
adding and removing the semi-colon after the macro invocation.

Here is some example code to test it against:

   fn foo() -> i32 {
       4
   }
   
   fn main() {
       println!("{:?}", foo());
   }

Thanks