Skip to content

Commit 2e4c4c5

Browse files
Jared Ramirezthe-mikedavis
authored andcommitted
Upgrade rescript tree sitter & highlights (helix-editor#4356)
Co-authored-by: Michael Davis <[email protected]>
1 parent 5062681 commit 2e4c4c5

File tree

5 files changed

+169
-24
lines changed

5 files changed

+169
-24
lines changed

languages.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ indent = { tab-width = 2, unit = " " }
11401140

11411141
[[grammar]]
11421142
name = "rescript"
1143-
source = { git = "https://github.com/jaredramirez/tree-sitter-rescript", rev = "4cd7ba91696886fdaca086fb32b5fd8cc294a129" }
1143+
source = { git = "https://github.com/jaredramirez/tree-sitter-rescript", rev = "65609807c628477f3b94052e7ef895885ac51c3c" }
11441144

11451145
[[language]]
11461146
name = "erlang"

runtime/queries/rescript/highlights.scm

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010
[
1111
(type_identifier)
1212
(unit_type)
13-
"list"
1413
] @type
1514

15+
(list ["list{" "}"] @type)
16+
(list_pattern ["list{" "}"] @type)
17+
1618
[
1719
(variant_identifier)
1820
(polyvar_identifier)
19-
] @constant
21+
] @constructor
2022

21-
(property_identifier) @variable.other.member
23+
(record_type_field (property_identifier) @type)
24+
(object_type (field (property_identifier) @type))
25+
(record_field (property_identifier) @variable.other.member)
26+
(object (field (property_identifier) @variable.other.member))
27+
(member_expression (property_identifier) @variable.other.member)
2228
(module_identifier) @namespace
2329

24-
(jsx_identifier) @tag
25-
(jsx_attribute (property_identifier) @variable.parameter)
26-
2730
; Parameters
2831
;----------------
2932

@@ -42,8 +45,8 @@
4245
"${" @punctuation.bracket
4346
"}" @punctuation.bracket) @embedded
4447

45-
(character) @constant.character
46-
(escape_sequence) @constant.character.escape
48+
(character) @string.special
49+
(escape_sequence) @string.special
4750

4851
; Other literals
4952
;---------------
@@ -60,11 +63,13 @@
6063
; Functions
6164
;----------
6265

66+
; parameter(s) in parens
6367
[
64-
(formal_parameters (value_identifier))
68+
(parameter (value_identifier))
6569
(labeled_parameter (value_identifier))
6670
] @variable.parameter
6771

72+
; single parameter with no parens
6873
(function parameter: (value_identifier) @variable.parameter)
6974

7075
; Meta
@@ -74,47 +79,65 @@
7479
"@"
7580
"@@"
7681
(decorator_identifier)
77-
] @label
82+
] @keyword.directive
7883

7984
(extension_identifier) @keyword
8085
("%") @keyword
8186

8287
; Misc
8388
;-----
8489

85-
(subscript_expression index: (string) @variable.other.member)
90+
; (subscript_expression index: (string) @attribute)
8691
(polyvar_type_pattern "#" @constant)
8792

8893
[
8994
("include")
9095
("open")
91-
] @keyword
96+
] @keyword.control.import
9297

9398
[
9499
"as"
95100
"export"
96101
"external"
97102
"let"
98103
"module"
99-
"mutable"
100104
"private"
101105
"rec"
102106
"type"
103107
"and"
104-
] @keyword
108+
"assert"
109+
"async"
110+
"await"
111+
"with"
112+
"unpack"
113+
] @keyword.storage.type
114+
115+
"mutable" @keyword.storage.modifier
105116

106117
[
107118
"if"
108119
"else"
109120
"switch"
110-
] @keyword
121+
"when"
122+
] @keyword.control.conditional
111123

112124
[
113125
"exception"
114126
"try"
115127
"catch"
116-
"raise"
117-
] @keyword
128+
] @keyword.control.exception
129+
130+
(call_expression
131+
function: (value_identifier) @keyword.control.exception
132+
(#eq? @keyword.control.exception "raise"))
133+
134+
[
135+
"for"
136+
"in"
137+
"to"
138+
"downto"
139+
"while"
140+
] @keyword.control.conditional
118141

119142
[
120143
"."
@@ -129,17 +152,15 @@
129152
"-"
130153
"-."
131154
"*"
155+
"**"
132156
"*."
133-
"/"
134157
"/."
135-
"<"
136158
"<="
137159
"=="
138160
"==="
139161
"!"
140162
"!="
141163
"!=="
142-
">"
143164
">="
144165
"&&"
145166
"||"
@@ -151,6 +172,10 @@
151172
(uncurry)
152173
] @operator
153174

175+
; Explicitly enclose these operators with binary_expression
176+
; to avoid confusion with JSX tag delimiters
177+
(binary_expression ["<" ">" "/"] @operator)
178+
154179
[
155180
"("
156181
")"
@@ -172,7 +197,24 @@
172197
"~"
173198
"?"
174199
"=>"
200+
".."
175201
"..."
176-
] @punctuation
202+
] @punctuation.special
177203

178204
(ternary_expression ["?" ":"] @operator)
205+
206+
; JSX
207+
;----------
208+
(jsx_identifier) @tag
209+
(jsx_element
210+
open_tag: (jsx_opening_element ["<" ">"] @punctuation.special))
211+
(jsx_element
212+
close_tag: (jsx_closing_element ["<" "/" ">"] @punctuation.special))
213+
(jsx_self_closing_element ["/" ">" "<"] @punctuation.special)
214+
(jsx_fragment [">" "<" "/"] @punctuation.special)
215+
(jsx_attribute (property_identifier) @attribute)
216+
217+
; Error
218+
;----------
219+
220+
(ERROR) @keyword.control.exception

runtime/queries/rescript/injections.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
(#set! injection.language "javascript"))
66

77
((raw_gql) @injection.content
8-
(#set! injection.language "graphql"))
8+
(#set! injection.language "graphql"))

runtime/queries/rescript/locals.scm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(switch_expression) @local.scope
2+
(if_expression) @local.scope
3+
4+
; Definitions
5+
;------------
6+
(type_declaration) @local.defintion
7+
(let_binding) @local.defintion

runtime/queries/rescript/textobjects.scm

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,110 @@
33

44
(module_declaration definition: ((_) @class.inside)) @class.around
55

6+
; Blocks
7+
;-------
8+
9+
(block (_) @function.inside) @function.around
10+
611
; Functions
712
;----------
813

914
(function body: (_) @function.inside) @function.around
1015

16+
; Calls
17+
;------
18+
19+
(call_expression arguments: ((_) @parameter.inside)) @parameter.around
20+
1121
; Comments
1222
;---------
1323

1424
(comment) @comment.inside
15-
1625
(comment)+ @comment.around
26+
27+
; Parameters
28+
;-----------
29+
30+
(function parameter: (_) @parameter.inside @parameter.around)
31+
32+
(formal_parameters
33+
","
34+
. (_) @parameter.inside
35+
@parameter.around)
36+
(formal_parameters
37+
. (_) @parameter.inside
38+
. ","?
39+
@parameter.around)
40+
41+
(arguments
42+
"," @_arguments_start
43+
. (_) @parameter.inside
44+
@parameter.around)
45+
(arguments
46+
. (_) @parameter.inside
47+
. ","?
48+
@parameter.around)
49+
50+
(function_type_parameters
51+
","
52+
. (_) @parameter.inside
53+
@parameter.around)
54+
(function_type_parameters
55+
. (_) @parameter.inside
56+
. ","?
57+
@parameter.around)
58+
59+
(functor_parameters
60+
","
61+
. (_) @parameter.inside
62+
@parameter.around)
63+
(functor_parameters
64+
. (_) @parameter.inside
65+
. ","?
66+
@parameter.around)
67+
68+
(type_parameters
69+
","
70+
. (_) @parameter.inside
71+
@parameter.around)
72+
(type_parameters
73+
. (_) @parameter.inside
74+
. ","?
75+
@parameter.around)
76+
77+
(type_arguments
78+
","
79+
. (_) @parameter.inside
80+
@parameter.around)
81+
(type_arguments
82+
. (_) @parameter.inside
83+
. ","?
84+
@parameter.around)
85+
86+
(decorator_arguments
87+
","
88+
. (_) @parameter.inside
89+
@parameter.around)
90+
(decorator_arguments
91+
. (_) @parameter.inside
92+
. ","?
93+
@parameter.around)
94+
95+
(variant_parameters
96+
","
97+
. (_) @parameter.inside
98+
@parameter.around)
99+
(variant_parameters
100+
. (_) @parameter.inside
101+
. ","?
102+
@parameter.around)
103+
104+
(polyvar_parameters
105+
","
106+
. (_) @parameter.inside
107+
@parameter.around)
108+
(polyvar_parameters
109+
. (_) @parameter.inside
110+
. ","?
111+
@parameter.around)
112+

0 commit comments

Comments
 (0)