Skip to content

Commit 6e4a9d0

Browse files
Update to latest tree-sitter-crystal
Highlighting, injection, and outline improvements
1 parent 90327f5 commit 6e4a9d0

File tree

5 files changed

+81
-52
lines changed

5 files changed

+81
-52
lines changed

extension.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ schema_version = 1
77
version = "0.0.3"
88

99
[grammars.crystal]
10-
commit = "cd3ae0751a58bca9fe875e580102578f5228a5a1"
10+
commit = "2af0dc12e65b98ea4c9737f645776277ef8d8f55"
1111
repository = "https://github.com/crystal-lang-tools/tree-sitter-crystal"
1212

1313
[grammars.ecr]

languages/crystal/embedding.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
(method_def
2929
"def" @name
3030
name: (_) @name)
31+
(abstract_method_def
32+
"def" @name
33+
name: (_) @name)
3134
(module_def
3235
"module" @name
3336
name: (_) @name)

languages/crystal/highlights.scm

Lines changed: 69 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
[
2+
","
3+
";"
4+
"."
5+
":"
6+
"*"
7+
"**"
8+
] @punctuation.delimiter
9+
110
[
211
"alias"
312
"alignof"
413
"annotation"
14+
"asm"
515
"begin"
616
"break"
717
"case"
@@ -65,12 +75,34 @@
6575
(pseudo_constant) @constant
6676

6777
; literals
68-
[
69-
(string)
70-
(char)
71-
] @string
78+
(char
79+
["'" (literal_content)] @string.special)
80+
81+
(char
82+
(escape_sequence) @string.escape)
83+
84+
(string
85+
["\"" (literal_content)] @string)
7286

73-
(symbol) @string.special.symbol
87+
(string
88+
(escape_sequence) @string.escape)
89+
90+
(symbol
91+
[
92+
":"
93+
":\""
94+
"\""
95+
(literal_content)
96+
] @string.special.symbol)
97+
98+
(symbol
99+
(escape_sequence) @string.escape)
100+
101+
(command
102+
["`" (literal_content)] @string.special)
103+
104+
(command
105+
(escape_sequence) @string.escape)
74106

75107
(regex
76108
"/" @punctuation.bracket)
@@ -80,14 +112,16 @@
80112

81113
(regex_modifier) @string.special.symbol
82114

83-
(heredoc_content) @string
115+
(heredoc_body
116+
(literal_content) @string)
117+
118+
(heredoc_body
119+
(escape_sequence) @string.escape)
84120

85121
[
86122
(heredoc_start)
87123
(heredoc_end)
88-
] @label
89-
90-
(string_escape_sequence) @string.escape
124+
] @string.escape
91125

92126
[
93127
(integer)
@@ -110,6 +144,7 @@
110144
(class_def)
111145
(struct_def)
112146
(method_def)
147+
(abstract_method_def)
113148
(macro_def)
114149
(module_def)
115150
(enum_def)
@@ -128,52 +163,30 @@
128163
"="
129164
"=>"
130165
"->"
131-
"+="
132-
"&+="
133-
"-="
134-
"&-="
135-
"*="
136-
"&*="
137-
"/="
138-
"//="
139-
"%="
140-
"|="
141-
"&="
142-
"^="
143-
"**="
144-
"<<="
145-
">>="
146-
"||="
147-
"&&="
166+
"&"
167+
(operator)
148168
] @operator
149169

150-
(operator) @operator
151-
152-
[
153-
","
154-
";"
155-
"."
156-
] @punctuation.delimiter
157-
158170
[
159171
"("
160172
")"
161173
"["
174+
"@["
162175
"]"
163176
"{"
164177
"}"
165178
] @punctuation.bracket
166179

167-
(annotation
168-
"@[" @punctuation.bracket)
169-
170180
(index_call
171181
method: (operator) @punctuation.bracket
172182
[
173183
"]"
174184
"]?"
175185
] @punctuation.bracket)
176186

187+
(block
188+
"|" @punctuation.bracket)
189+
177190
[
178191
"{%"
179192
"%}"
@@ -187,6 +200,8 @@
187200

188201
(identifier) @variable
189202

203+
; TODO: {splat,double_splat,block,fun}_param + rescue param
204+
190205
; Types
191206
[
192207
(constant)
@@ -200,20 +215,24 @@
200215
(nilable_type
201216
"?" @type)
202217

218+
(union_type
219+
"|" @operator)
220+
203221
(annotation
204222
(constant) @attribute)
205223

206224
(method_def
207-
name: [
208-
(identifier)
209-
(constant)
210-
] @function)
225+
name: (identifier) @function)
211226

212227
(macro_def
213-
name: [
214-
(identifier)
215-
(constant)
216-
] @function)
228+
name: (identifier) @function)
229+
230+
(abstract_method_def
231+
name: (identifier) @function)
232+
233+
(fun_def
234+
name: (identifier) @function
235+
real_name: (identifier)? @function)
217236

218237
(macro_var) @variable
219238

@@ -223,13 +242,13 @@
223242
] @property
224243

225244
(named_expr
226-
name: (_) @label
227-
":" @label)
245+
name: (identifier) @property
246+
":" @property)
228247

229-
(underscore) @variable.special
248+
(named_type
249+
name: (identifier) @property)
230250

231-
(pointer_type
232-
"*" @operator)
251+
(underscore) @variable.special
233252

234253
; function calls
235254
(call

languages/crystal/injections.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(#set! injection.language "regex"))
44

55
(heredoc_body
6-
(heredoc_content) @injection.content
6+
(literal_content) @injection.content
77
(heredoc_end) @injection.language
88
(#downcase! injection.language))
99

languages/crystal/outline.scm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"." @context)?
1515
name: (_) @name) @item
1616

17+
(abstract_method_def
18+
"abstract" @context
19+
"def" @context
20+
((_) @context
21+
"." @context)?
22+
name: (_) @name) @item
23+
1724
(fun_def
1825
"fun" @context
1926
name: (_) @name

0 commit comments

Comments
 (0)