aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2023-02-14 19:29:30 +0200
committerDmitry Gutov2023-02-14 23:54:58 +0200
commit477aa047ee73d2b93c04a88700263e58cf7bab70 (patch)
treea808c0a8409855523909ebd44eb73f7a74f7a6b0
parent5206a551c166fc1908edff4fdf1695f7cef3600a (diff)
downloademacs-477aa047ee73d2b93c04a88700263e58cf7bab70.tar.gz
emacs-477aa047ee73d2b93c04a88700263e58cf7bab70.zip
rust-ts-mode: Highlight variable reassignments
* lisp/progmodes/rust-ts-mode.el (rust-ts-mode): New treesit font-lock feature: 'assignment' (bug#61302). (rust-ts-mode--fontify-pattern): Remove the node lookup step. (rust-ts-mode--font-lock-settings): Update variable declaration queries to match the 'pattern' child node right away. Add highlights for 'assignment.
-rw-r--r--lisp/progmodes/rust-ts-mode.el19
1 files changed, 12 insertions, 7 deletions
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index 5c71a8ad461..f709b16ff39 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -163,11 +163,16 @@
163 (macro_definition "macro_rules!" @font-lock-constant-face) 163 (macro_definition "macro_rules!" @font-lock-constant-face)
164 (macro_definition (identifier) @font-lock-preprocessor-face) 164 (macro_definition (identifier) @font-lock-preprocessor-face)
165 (field_declaration name: (field_identifier) @font-lock-property-face) 165 (field_declaration name: (field_identifier) @font-lock-property-face)
166 (parameter) @rust-ts-mode--fontify-pattern 166 (parameter pattern: (_) @rust-ts-mode--fontify-pattern)
167 (let_declaration) @rust-ts-mode--fontify-pattern 167 (let_declaration pattern: (_) @rust-ts-mode--fontify-pattern)
168 (for_expression) @rust-ts-mode--fontify-pattern 168 (for_expression pattern: (_) @rust-ts-mode--fontify-pattern)
169 (let_condition) @rust-ts-mode--fontify-pattern 169 (let_condition pattern: (_) @rust-ts-mode--fontify-pattern)
170 (match_arm) @rust-ts-mode--fontify-pattern) 170 (match_arm pattern: (_) @rust-ts-mode--fontify-pattern))
171
172 :language 'rust
173 :feature 'assignment
174 '((assignment_expression left: (_) @rust-ts-mode--fontify-pattern)
175 (compound_assignment_expr left: (_) @rust-ts-mode--fontify-pattern))
171 176
172 :language 'rust 177 :language 'rust
173 :feature 'function 178 :feature 'function
@@ -261,7 +266,7 @@
261 (treesit-available-p) 266 (treesit-available-p)
262 `(lambda (node override start end &rest _) 267 `(lambda (node override start end &rest _)
263 (let ((captures (treesit-query-capture 268 (let ((captures (treesit-query-capture
264 (treesit-node-child-by-field-name node "pattern") 269 node
265 ,(treesit-query-compile 'rust '((identifier) @id 270 ,(treesit-query-compile 'rust '((identifier) @id
266 (shorthand_field_identifier) @id))))) 271 (shorthand_field_identifier) @id)))))
267 (pcase-dolist (`(_name . ,id) captures) 272 (pcase-dolist (`(_name . ,id) captures)
@@ -342,7 +347,7 @@ delimiters < and >'s."
342 (setq-local treesit-font-lock-feature-list 347 (setq-local treesit-font-lock-feature-list
343 '(( comment definition) 348 '(( comment definition)
344 ( keyword string) 349 ( keyword string)
345 ( attribute builtin constant escape-sequence 350 ( assignment attribute builtin constant escape-sequence
346 number type) 351 number type)
347 ( bracket delimiter error function operator property variable))) 352 ( bracket delimiter error function operator property variable)))
348 353