Skip to content

Commit c6ddef2

Browse files
committed
Merge pull request #215 from zhengbli/fixSyntaxIssues
Fix highlighting issues for constructors containing type parameter
2 parents 6f52208 + 202c720 commit c6ddef2

File tree

2 files changed

+84
-13
lines changed

2 files changed

+84
-13
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,23 @@ repository:
133133
'2': { name: keyword.operator.ts }
134134
'3': { name: entity.name.function.ts }
135135
'4': { name: keyword.operator.ts }
136-
end: '(?=\}|;|,|\n)|(?<=\})'
136+
end: '(?=\}|;|,)|(?<=\})'
137137
patterns:
138138
- include: '#comment'
139139
- include: '#type-parameters'
140140
- include: '#function-type-parameters'
141141
- include: '#type-annotation'
142+
- include: '#method-overload-declaration'
142143
- include: '#decl-block'
143144

145+
method-overload-declaration:
146+
name: meta.method.overload.declaration.ts
147+
match: '(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
148+
captures:
149+
'1': { name: keyword.operator.ts }
150+
'2': { name: entity.name.function.ts }
151+
'3': { name: keyword.operator.ts }
152+
144153
indexer-declaration:
145154
name: meta.indexer.declaration.ts
146155
begin: \[
@@ -309,9 +318,10 @@ repository:
309318

310319
type-parameters:
311320
name: meta.type.parameters.ts
312-
begin: '<'
321+
begin: '([a-zA-Z_$][\w$]*)?(<)'
313322
beginCaptures:
314-
'0': { name: meta.brace.angle.ts }
323+
'1': { name: entity.name.type.ts }
324+
'2': { name: meta.brace.angle.ts }
315325
end: '(?=$)|(>)'
316326
endCaptures:
317327
'2': { name: meta.brace.angle.ts }
@@ -343,6 +353,7 @@ repository:
343353
- include: '#declaration'
344354
- include: '#cast'
345355
- include: '#new-expr'
356+
- include: '#function-call'
346357
- include: '#block'
347358
- include: '#expression-operator'
348359
- include: '#relational-operator'
@@ -359,7 +370,13 @@ repository:
359370
captures:
360371
'1': { name: storage.type.ts }
361372
'3': { name: keyword.operator.ts }
362-
373+
374+
function-call:
375+
name: functioncall.expr.ts
376+
patterns:
377+
- include: '#type-parameters'
378+
- include: '#paren-expression'
379+
363380
cast:
364381
name: cast.expr.ts
365382
# To differentiate a cast vs a relational <, this regexp tries to use the surrounding context
@@ -368,10 +385,10 @@ repository:
368385
# '<=' and '<<=' are definately not type assertions, as they are assignment operators.
369386
begin: '(?:(?<=return|throw|yield|[=(,:>]))\s*(<)(?!<?\=)'
370387
beginCaptures:
371-
'1': { name: keyword.operator.type.ts }
388+
'1': { name: meta.brace.angle.ts }
372389
end: '>'
373390
endCaptures:
374-
'0': { name: keyword.operator.type.ts }
391+
'0': { name: meta.brace.angle.ts }
375392
patterns:
376393
- include: '#type'
377394

@@ -381,7 +398,7 @@ repository:
381398
beginCaptures:
382399
'1': { name: keyword.operator.ts }
383400
# new-expr ends just before any type or call arguments. Type arguments will be picked up by #cast.
384-
end: '(?=[<(;]|$)'
401+
end: '(?=[(;]|$)'
385402
patterns:
386403
- include: '#type'
387404

TypeScript.tmLanguage

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
<key>1</key>
123123
<dict>
124124
<key>name</key>
125-
<string>keyword.operator.type.ts</string>
125+
<string>meta.brace.angle.ts</string>
126126
</dict>
127127
</dict>
128128
<key>end</key>
@@ -132,7 +132,7 @@
132132
<key>0</key>
133133
<dict>
134134
<key>name</key>
135-
<string>keyword.operator.type.ts</string>
135+
<string>meta.brace.angle.ts</string>
136136
</dict>
137137
</dict>
138138
<key>name</key>
@@ -328,6 +328,10 @@
328328
<key>include</key>
329329
<string>#new-expr</string>
330330
</dict>
331+
<dict>
332+
<key>include</key>
333+
<string>#function-call</string>
334+
</dict>
331335
<dict>
332336
<key>include</key>
333337
<string>#block</string>
@@ -422,6 +426,22 @@
422426
<key>name</key>
423427
<string>forin.expr.ts</string>
424428
</dict>
429+
<key>function-call</key>
430+
<dict>
431+
<key>name</key>
432+
<string>functioncall.expr.ts</string>
433+
<key>patterns</key>
434+
<array>
435+
<dict>
436+
<key>include</key>
437+
<string>#type-parameters</string>
438+
</dict>
439+
<dict>
440+
<key>include</key>
441+
<string>#paren-expression</string>
442+
</dict>
443+
</array>
444+
</dict>
425445
<key>function-declaration</key>
426446
<dict>
427447
<key>begin</key>
@@ -662,7 +682,7 @@
662682
</dict>
663683
</dict>
664684
<key>end</key>
665-
<string>(?=\}|;|,|\n)|(?&lt;=\})</string>
685+
<string>(?=\}|;|,)|(?&lt;=\})</string>
666686
<key>name</key>
667687
<string>meta.method.declaration.ts</string>
668688
<key>patterns</key>
@@ -683,12 +703,41 @@
683703
<key>include</key>
684704
<string>#type-annotation</string>
685705
</dict>
706+
<dict>
707+
<key>include</key>
708+
<string>#method-overload-declaration</string>
709+
</dict>
686710
<dict>
687711
<key>include</key>
688712
<string>#decl-block</string>
689713
</dict>
690714
</array>
691715
</dict>
716+
<key>method-overload-declaration</key>
717+
<dict>
718+
<key>captures</key>
719+
<dict>
720+
<key>1</key>
721+
<dict>
722+
<key>name</key>
723+
<string>keyword.operator.ts</string>
724+
</dict>
725+
<key>2</key>
726+
<dict>
727+
<key>name</key>
728+
<string>entity.name.function.ts</string>
729+
</dict>
730+
<key>3</key>
731+
<dict>
732+
<key>name</key>
733+
<string>keyword.operator.ts</string>
734+
</dict>
735+
</dict>
736+
<key>match</key>
737+
<string>(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\&lt;)</string>
738+
<key>name</key>
739+
<string>meta.method.overload.declaration.ts</string>
740+
</dict>
692741
<key>new-expr</key>
693742
<dict>
694743
<key>begin</key>
@@ -702,7 +751,7 @@
702751
</dict>
703752
</dict>
704753
<key>end</key>
705-
<string>(?=[&lt;(;]|$)</string>
754+
<string>(?=[(;]|$)</string>
706755
<key>name</key>
707756
<string>new.expr.ts</string>
708757
<key>patterns</key>
@@ -1361,10 +1410,15 @@
13611410
<key>type-parameters</key>
13621411
<dict>
13631412
<key>begin</key>
1364-
<string>&lt;</string>
1413+
<string>([a-zA-Z_$][\w$]*)?(&lt;)</string>
13651414
<key>beginCaptures</key>
13661415
<dict>
1367-
<key>0</key>
1416+
<key>1</key>
1417+
<dict>
1418+
<key>name</key>
1419+
<string>entity.name.type.ts</string>
1420+
</dict>
1421+
<key>2</key>
13681422
<dict>
13691423
<key>name</key>
13701424
<string>meta.brace.angle.ts</string>

0 commit comments

Comments
 (0)