Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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)
Expand Down
2 changes: 0 additions & 2 deletions runtime/queries/rust/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@
"dyn"
] @keyword.storage.modifier

; TODO: variable.mut to highlight mutable identifiers via locals.scm

; ---
; Remaining Paths
; ---
Expand Down
14 changes: 14 additions & 0 deletions runtime/queries/rust/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,19 @@

(closure_parameters (identifier) @local.definition.variable.parameter)

; Mutable variables

[
(let_declaration
(mutable_specifier)
pattern: (identifier) @local.definition.variable.mutable @variable.mutable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both here and #14352 you should only write local.definition.*, local.scope, local.reference or throwaway captures in the locals.scm file, not highlight captures. I think it's necessary to make some highlights work currently but it's a bug in locals if it's required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious - why is it a bug?

anyway, I have "fixed" this by just duplicating the query. I wish there was a more elegant solution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The locals.scm queries should be separate from highlights and ideally have separate precedence too, so you could hypothetically say

; All parameters are variable.parameter
(parameter) @local.definition.variable.parameter
; Except builtins
((parameter) @_self (#eq? @_self "self"))

Ideally you should also not need to duplicate the highlights between locals.scm and highlights.scm: the locals should take precedence when they match. This needs a bit of work in tree-house to get right.

(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
Loading