From afb02f66a3992e41cae4d8db9e26de9ef677ec88 Mon Sep 17 00:00:00 2001 From: Jonathan Andersson Date: Fri, 8 Aug 2025 00:16:19 +0200 Subject: [PATCH 1/5] Capture `shorthand_field_initializer` in rust highlights Currently shorthand field initializers are not captured the same way as the full initializers leading to awkward and mismatching highlighting. In addition, captures the `!` as part of a macro invocation. --- crates/languages/src/rust/highlights.scm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/languages/src/rust/highlights.scm b/crates/languages/src/rust/highlights.scm index 1c46061827cd50..3b7861a0242150 100644 --- a/crates/languages/src/rust/highlights.scm +++ b/crates/languages/src/rust/highlights.scm @@ -6,6 +6,9 @@ (self) @variable.special (field_identifier) @property +(shorthand_field_initializer + (identifier) @property) + (trait_item name: (type_identifier) @type.interface) (impl_item trait: (type_identifier) @type.interface) (abstract_type trait: (type_identifier) @type.interface) @@ -38,7 +41,8 @@ (identifier) @function.special (scoped_identifier name: (identifier) @function.special) - ]) + ] + "!" @function.special) (macro_definition name: (identifier) @function.special.definition) From 8896e870bf5a9e3a1ddcf0df90f5f818902098be Mon Sep 17 00:00:00 2001 From: Jonathan Andersson Date: Fri, 8 Aug 2025 17:33:26 +0200 Subject: [PATCH 2/5] Capture rust module namespaces as `@module` --- crates/languages/src/rust/highlights.scm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/languages/src/rust/highlights.scm b/crates/languages/src/rust/highlights.scm index 3b7861a0242150..3f63caf96b6f7c 100644 --- a/crates/languages/src/rust/highlights.scm +++ b/crates/languages/src/rust/highlights.scm @@ -47,6 +47,21 @@ (macro_definition name: (identifier) @function.special.definition) +[ + (crate) + (super) +] @module + +(mod_item + name: (identifier) @module) + +(scoped_use_list + path: (identifier) @module) + +(scoped_use_list + path: (scoped_identifier + (identifier) @module)) + ; Identifier conventions ; Assume uppercase names are types/enum-constructors @@ -119,9 +134,7 @@ "where" "while" "yield" - (crate) (mutable_specifier) - (super) ] @keyword [ From e780c7a9663c35553ff71fe18b1da56afd07f633 Mon Sep 17 00:00:00 2001 From: Jonathan Andersson Date: Sat, 9 Aug 2025 18:11:16 +0200 Subject: [PATCH 3/5] Capture identifier as part of lifetime highlight --- crates/languages/src/rust/highlights.scm | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/languages/src/rust/highlights.scm b/crates/languages/src/rust/highlights.scm index 3f63caf96b6f7c..d0635c6d808a6d 100644 --- a/crates/languages/src/rust/highlights.scm +++ b/crates/languages/src/rust/highlights.scm @@ -206,6 +206,7 @@ operator: "/" @operator (lifetime) @lifetime +(lifetime (identifier) @lifetime) (parameter (identifier) @variable.parameter) From 659993cb7d827051b1ab641472b8c0ed908bd870 Mon Sep 17 00:00:00 2001 From: Jonathan Andersson Date: Sat, 9 Aug 2025 19:18:41 +0200 Subject: [PATCH 4/5] Improve captures for use statements This should rather be done in a separate PR as its a more sizable edit --- crates/languages/src/rust/highlights.scm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/languages/src/rust/highlights.scm b/crates/languages/src/rust/highlights.scm index d0635c6d808a6d..414da8a49d4564 100644 --- a/crates/languages/src/rust/highlights.scm +++ b/crates/languages/src/rust/highlights.scm @@ -47,20 +47,24 @@ (macro_definition name: (identifier) @function.special.definition) -[ - (crate) - (super) -] @module - (mod_item name: (identifier) @module) -(scoped_use_list - path: (identifier) @module) +[ + (crate) @module + (super) @module +] + +path: (scoped_identifier + (identifier) @module) +path: (identifier) @module + +(use_wildcard (identifier) @module) -(scoped_use_list - path: (scoped_identifier - (identifier) @module)) +(visibility_modifier [ + (crate) @keyword + (super) @keyword +]) ; Identifier conventions From 32e04f4158516a6228c800362f828f1c35f480bf Mon Sep 17 00:00:00 2001 From: Jonathan Andersson Date: Wed, 13 Aug 2025 17:36:41 +0200 Subject: [PATCH 5/5] Remove module captures --- crates/languages/src/rust/highlights.scm | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/crates/languages/src/rust/highlights.scm b/crates/languages/src/rust/highlights.scm index 414da8a49d4564..9c02fbedaa6bc9 100644 --- a/crates/languages/src/rust/highlights.scm +++ b/crates/languages/src/rust/highlights.scm @@ -50,17 +50,6 @@ (mod_item name: (identifier) @module) -[ - (crate) @module - (super) @module -] - -path: (scoped_identifier - (identifier) @module) -path: (identifier) @module - -(use_wildcard (identifier) @module) - (visibility_modifier [ (crate) @keyword (super) @keyword