From a2f219968a8f6b9ef193eb76a92ed913929d91e6 Mon Sep 17 00:00:00 2001 From: Nik Revenco Date: Mon, 14 Jul 2025 02:28:50 +0100 Subject: [PATCH] queries: Highlight mutable variables in Rust --- book/src/themes.md | 1 + runtime/queries/rust/highlights.scm | 2 -- runtime/queries/rust/locals.scm | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/book/src/themes.md b/book/src/themes.md index 3ef064d6d..faac0841f 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -179,6 +179,7 @@ We use a similar set of scopes as - `variable` - Variables - `builtin` - Reserved language variables (`self`, `this`, `super`, etc.) - `parameter` - Function parameters + - `mutable` - Mutable variables (e.g. marked with `mut` in Rust) - `other` - `member` - Fields of composite data types (e.g. structs, unions) - `private` - Private fields that use a unique syntax (currently just ECMAScript-based languages) diff --git a/runtime/queries/rust/highlights.scm b/runtime/queries/rust/highlights.scm index 5e3471b36..4e7d79f20 100644 --- a/runtime/queries/rust/highlights.scm +++ b/runtime/queries/rust/highlights.scm @@ -289,8 +289,6 @@ "dyn" ] @keyword.storage.modifier -; TODO: variable.mut to highlight mutable identifiers via locals.scm - ; --- ; Remaining Paths ; --- diff --git a/runtime/queries/rust/locals.scm b/runtime/queries/rust/locals.scm index 3262f9473..1aca98ff8 100644 --- a/runtime/queries/rust/locals.scm +++ b/runtime/queries/rust/locals.scm @@ -12,7 +12,7 @@ (block) ] @local.scope -; Definitions +; Parameters (parameter pattern: [ @@ -39,5 +39,19 @@ ) ]) +; Mutable variables + +[ + (let_declaration + (mutable_specifier) + pattern: (identifier) @local.definition.variable.mutable @variable.mutable) + (parameter + (mutable_specifier) + pattern: (identifier) @local.definition.variable.mutable @variable.mutable) + (mut_pattern + (mutable_specifier) + (identifier) @local.definition.variable.mutable @variable.mutable) +] + ; References (identifier) @local.reference