Skip to content

Commit a8f7b3c

Browse files
committed
Expose brackets and template tag name
Some editor features requires the abillity to capture the brackets independent from the tag name. e.g. Zed captures `<` as brackets and highlight them different from the tag name. It uses it to highlight the opposite opening/closing pair when the cursor is on one of the brackets.
1 parent ac9b8f8 commit a8f7b3c

File tree

5 files changed

+194967
-195117
lines changed

5 files changed

+194967
-195117
lines changed

grammar.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ module.exports = grammar(TypeScript, {
3535
field("close_tag", $.glimmer_closing_tag),
3636
),
3737

38-
_glimmer_template_content: (_) => /.{1,}/,
39-
glimmer_opening_tag: (_) => "<template>",
40-
glimmer_closing_tag: (_) => "</template>",
38+
glimmer_opening_tag: ($) => seq("<", $.glimmer_template_tag_name, ">"),
39+
glimmer_closing_tag: ($) => seq("</", $.glimmer_template_tag_name, ">"),
40+
glimmer_template_tag_name: (_) => "template",
4141

4242
/**
4343
* 2. Any Expression.

src/grammar.json

+34-4
Original file line numberDiff line numberDiff line change
@@ -2790,12 +2790,38 @@
27902790
"value": ".{1,}"
27912791
},
27922792
"glimmer_opening_tag": {
2793-
"type": "STRING",
2794-
"value": "<template>"
2793+
"type": "SEQ",
2794+
"members": [
2795+
{
2796+
"type": "STRING",
2797+
"value": "<"
2798+
},
2799+
{
2800+
"type": "SYMBOL",
2801+
"name": "glimmer_template_tag_name"
2802+
},
2803+
{
2804+
"type": "STRING",
2805+
"value": ">"
2806+
}
2807+
]
27952808
},
27962809
"glimmer_closing_tag": {
2797-
"type": "STRING",
2798-
"value": "</template>"
2810+
"type": "SEQ",
2811+
"members": [
2812+
{
2813+
"type": "STRING",
2814+
"value": "</"
2815+
},
2816+
{
2817+
"type": "SYMBOL",
2818+
"name": "glimmer_template_tag_name"
2819+
},
2820+
{
2821+
"type": "STRING",
2822+
"value": ">"
2823+
}
2824+
]
27992825
},
28002826
"_jsx_element": {
28012827
"type": "CHOICE",
@@ -11137,6 +11163,10 @@
1113711163
},
1113811164
"named": true,
1113911165
"value": "type_identifier"
11166+
},
11167+
"glimmer_template_tag_name": {
11168+
"type": "STRING",
11169+
"value": "template"
1114011170
}
1114111171
},
1114211172
"extras": [

src/node-types.json

+35-5
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,36 @@
27272727
}
27282728
}
27292729
},
2730+
{
2731+
"type": "glimmer_closing_tag",
2732+
"named": true,
2733+
"fields": {},
2734+
"children": {
2735+
"multiple": false,
2736+
"required": true,
2737+
"types": [
2738+
{
2739+
"type": "glimmer_template_tag_name",
2740+
"named": true
2741+
}
2742+
]
2743+
}
2744+
},
2745+
{
2746+
"type": "glimmer_opening_tag",
2747+
"named": true,
2748+
"fields": {},
2749+
"children": {
2750+
"multiple": false,
2751+
"required": true,
2752+
"types": [
2753+
{
2754+
"type": "glimmer_template_tag_name",
2755+
"named": true
2756+
}
2757+
]
2758+
}
2759+
},
27302760
{
27312761
"type": "glimmer_template",
27322762
"named": true,
@@ -5573,6 +5603,10 @@
55735603
"type": "<",
55745604
"named": false
55755605
},
5606+
{
5607+
"type": "</",
5608+
"named": false
5609+
},
55765610
{
55775611
"type": "<<",
55785612
"named": false
@@ -5798,11 +5832,7 @@
57985832
"named": false
57995833
},
58005834
{
5801-
"type": "glimmer_closing_tag",
5802-
"named": true
5803-
},
5804-
{
5805-
"type": "glimmer_opening_tag",
5835+
"type": "glimmer_template_tag_name",
58065836
"named": true
58075837
},
58085838
{

0 commit comments

Comments
 (0)