From 4efff2fe80c0ec4476d3a28370fd32e511479ed4 Mon Sep 17 00:00:00 2001 From: Joey Hain Date: Sun, 29 Oct 2023 11:24:46 -0700 Subject: [PATCH 1/2] rust: add highlight scope for type parameters --- book/src/themes.md | 1 + runtime/queries/rust/highlights.scm | 5 +++++ runtime/queries/rust/locals.scm | 13 ++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/book/src/themes.md b/book/src/themes.md index 661210765fb6..a62c07feee02 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -155,6 +155,7 @@ We use a similar set of scopes as - `type` - Types - `builtin` - Primitive types provided by the language (`int`, `usize`) + - `parameter` - Generic type parameters (`T`) - `enum` - `variant` - `constructor` diff --git a/runtime/queries/rust/highlights.scm b/runtime/queries/rust/highlights.scm index bf2fde4995c7..adb1d522d4d7 100644 --- a/runtime/queries/rust/highlights.scm +++ b/runtime/queries/rust/highlights.scm @@ -9,6 +9,11 @@ ; Types ; ------- +(type_parameters + (type_identifier) @type.parameter) +(constrained_type_parameter + left: (type_identifier) @type.parameter) + ; --- ; Primitives ; --- diff --git a/runtime/queries/rust/locals.scm b/runtime/queries/rust/locals.scm index 75e5d181c13a..23967fcdfefe 100644 --- a/runtime/queries/rust/locals.scm +++ b/runtime/queries/rust/locals.scm @@ -2,6 +2,12 @@ [ (function_item) + (struct_item) + (enum_item) + (union_item) + (type_item) + (trait_item) + (impl_item) (closure_expression) (block) ] @local.scope @@ -11,8 +17,13 @@ (parameter (identifier) @local.definition) +(type_parameters + (type_identifier) @local.definition) +(constrained_type_parameter + left: (type_identifier) @local.definition) + (closure_parameters (identifier) @local.definition) ; References (identifier) @local.reference - +(type_identifier) @local.reference From 766c1807e361456269b3fec8f8690f87107f8285 Mon Sep 17 00:00:00 2001 From: Joey Hain Date: Mon, 30 Oct 2023 08:20:43 -0700 Subject: [PATCH 2/2] handle optional type parameters --- runtime/queries/rust/highlights.scm | 2 ++ runtime/queries/rust/locals.scm | 2 ++ 2 files changed, 4 insertions(+) diff --git a/runtime/queries/rust/highlights.scm b/runtime/queries/rust/highlights.scm index adb1d522d4d7..47e57e8008d6 100644 --- a/runtime/queries/rust/highlights.scm +++ b/runtime/queries/rust/highlights.scm @@ -13,6 +13,8 @@ (type_identifier) @type.parameter) (constrained_type_parameter left: (type_identifier) @type.parameter) +(optional_type_parameter + name: (type_identifier) @type.parameter) ; --- ; Primitives diff --git a/runtime/queries/rust/locals.scm b/runtime/queries/rust/locals.scm index 23967fcdfefe..cb75d15578cd 100644 --- a/runtime/queries/rust/locals.scm +++ b/runtime/queries/rust/locals.scm @@ -21,6 +21,8 @@ (type_identifier) @local.definition) (constrained_type_parameter left: (type_identifier) @local.definition) +(optional_type_parameter + name: (type_identifier) @local.definition) (closure_parameters (identifier) @local.definition)