on master help sign in
Add parameter highlights to Erlang

This doesn't work robustly (within pattern matches). Only regular bindings are highlighted as parameters. In order to highlight all parameters even in matches, we would need an arbitrary nesting operator in queries which doesn't exist yet in tree-sitter.

commit5a1bed2b708f6874daa9f04b26b14b3106d2e447 authorMichael Davis <mcarsondavis@gmail.com> dateWed 2 Nov 2022, 09:38 (4 years ago) parent452f7d0
2 files changed+61−3
runtime/queries/erlang/highlights.scm+31−3 runtime/queries/erlang/locals.scm+30
runtime/queries/erlang/highlights.scm+31−3
@@ -65,6 +65,37 @@
6565(function_capture module: (atom) @namespace)
6666(function_capture function: (atom) @function)
6767
68+; Ignored variables
69+((variable) @comment.discard
70+ (#match? @comment.discard "^_"))
71+
72+; Parameters
73+; specs
74+((attribute
75+ name: (atom) @keyword
76+ (stab_clause
77+ pattern: (arguments (variable) @variable.parameter)
78+ body: (variable)? @variable.parameter))
79+ (#match? @keyword "(spec|callback)"))
80+; functions
81+(function_clause pattern: (arguments (variable) @variable.parameter))
82+; anonymous functions
83+(stab_clause pattern: (arguments (variable) @variable.parameter))
84+; parametric types
85+((attribute
86+ name: (atom) @keyword
87+ (arguments
88+ (binary_operator
89+ left: (call (arguments (variable) @variable.parameter))
90+ operator: "::")))
91+ (#match? @keyword "(type|opaque)"))
92+; macros
93+((attribute
94+ name: (atom) @keyword
95+ (arguments
96+ (call (arguments (variable) @variable.parameter))))
97+ (#eq? @keyword "define"))
98+
6899; Records
69100(record_content
70101 (binary_operator
@@ -105,9 +136,6 @@
105136 name: (_) @keyword.directive)
106137
107138; Comments
108−((variable) @comment.discard
109− (#match? @comment.discard "^_"))
110−
111139(tripledot) @comment.discard
112140
113141[(comment) (line_comment) (shebang)] @comment
runtime/queries/erlang/locals.scmnew file+30
@@ -0,0 +1,30 @@
1+; Specs and Callbacks
2+(attribute
3+ (stab_clause
4+ pattern: (arguments (variable) @local.definition)
5+ ; If a spec uses a variable as the return type (and later a `when` clause to type it):
6+ body: (variable)? @local.definition)) @local.scope
7+
8+; parametric `-type`s
9+((attribute
10+ name: (atom) @_type
11+ (arguments
12+ (binary_operator
13+ left: (call (arguments (variable) @local.definition))
14+ operator: "::") @local.scope))
15+ (#match? @_type "(type|opaque)"))
16+
17+; macros
18+((attribute
19+ name: (atom) @_define
20+ (arguments
21+ (call (arguments (variable) @local.definition)))) @local.scope
22+ (#eq? @_define "define"))
23+
24+; `fun`s
25+(anonymous_function (stab_clause pattern: (arguments (variable) @local.definition))) @local.scope
26+
27+; Ordinary functions
28+(function_clause pattern: (arguments (variable) @local.definition)) @local.scope
29+
30+(variable) @local.reference