astro-vscode 0.29.0 → 0.29.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  "color": "#FFBE2D",
24
24
  "theme": "dark"
25
25
  },
26
- "version": "0.29.0",
26
+ "version": "0.29.3",
27
27
  "author": "withastro",
28
28
  "license": "MIT",
29
29
  "publisher": "astro-build",
@@ -35,19 +35,21 @@
35
35
  "workspaceContains:astro.config.*"
36
36
  ],
37
37
  "dependencies": {
38
- "@astrojs/compiler": "^0.29.15",
39
- "@astrojs/ts-plugin": "0.4.0",
38
+ "@astrojs/compiler": "^0.31.3",
39
+ "synckit": "0.8.4",
40
+ "@astrojs/ts-plugin": "0.4.1",
40
41
  "prettier": "^2.7.1",
41
42
  "prettier-plugin-astro": "^0.7.0"
42
43
  },
43
44
  "devDependencies": {
44
- "@astrojs/language-server": "0.29.0",
45
+ "@astrojs/language-server": "0.29.3",
45
46
  "@types/mocha": "^9.1.0",
46
47
  "@types/vscode": "^1.67.0",
47
48
  "@vscode/test-electron": "^2.1.3",
48
49
  "esbuild": "0.14.54",
49
50
  "esbuild-plugin-copy": "^1.3.0",
50
51
  "glob": "^8.0.3",
52
+ "js-yaml": "^4.1.0",
51
53
  "kleur": "^4.1.5",
52
54
  "mocha": "^9.2.2",
53
55
  "path-browserify": "^1.0.1",
@@ -358,9 +360,10 @@
358
360
  "build:browser": "node ./scripts/build-browser.js",
359
361
  "build:ci:node": "pnpm build:node & pnpm build:browser --empty",
360
362
  "build:ci:browser": "pnpm build:browser & pnpm build:node --empty",
363
+ "build:grammar": "npx js-yaml syntaxes/astro.tmLanguage.src.yaml > syntaxes/astro.tmLanguage.json",
361
364
  "test": "pnpm test:vscode && pnpm test:grammar",
362
365
  "test:vscode": "node ./test/runTest.js",
363
- "test:grammar": "node ./test/grammar/test.mjs",
366
+ "test:grammar": "pnpm build:grammar && node ./test/grammar/test.mjs",
364
367
  "update-grammar-snapshots": "node ./test/grammar/test.mjs --updateSnapshot"
365
368
  }
366
369
  }
@@ -0,0 +1,465 @@
1
+ ---
2
+ # Adapted from Svelte's syntax file at
3
+ # https://github.com/sveltejs/language-tools/blob/240e640903237a2d605242a163970ab8c704724f/packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml
4
+ name: Astro
5
+ scopeName: source.astro
6
+ fileTypes: [astro]
7
+
8
+ injections:
9
+ # ---- EMBEDDED LANGUAGES
10
+
11
+ # Format:
12
+ # 'L:meta.<script|style|template>.astro (meta.lang.<lang> | meta.lang.<langalternative> | ...) - (meta source)'
13
+ # patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.astro,
14
+ # contentName: source.<lang>, patterns: [{ include: source.<lang> }]}]
15
+
16
+ # Style/Script Languages
17
+ # JSON | 'application/ld+json'
18
+ 'L:(meta.script.astro) (meta.lang.json) - (meta source)':
19
+ patterns:
20
+ [
21
+ {
22
+ begin: '(?<=>)(?!</)',
23
+ end: '(?=</)',
24
+ name: meta.embedded.block.astro,
25
+ contentName: source.json,
26
+ patterns: [{ include: source.json }],
27
+ },
28
+ ]
29
+
30
+ # JavaScript | 'javascript' | 'source.js' | 'partytown'
31
+ 'L:(meta.script.astro) (meta.lang.js | meta.lang.javascript | meta.lang.partytown | meta.lang.node) - (meta source)':
32
+ patterns:
33
+ [
34
+ {
35
+ begin: '(?<=>)(?!</)',
36
+ end: '(?=</)',
37
+ name: meta.embedded.block.astro,
38
+ contentName: source.js,
39
+ patterns: [{ include: source.js }],
40
+ },
41
+ ]
42
+
43
+ # TypeScript | 'ts'
44
+ 'L:(meta.script.astro) (meta.lang.ts | meta.lang.typescript) - (meta source)':
45
+ patterns:
46
+ [
47
+ {
48
+ begin: '(?<=>)(?!</)',
49
+ end: '(?=</)',
50
+ name: meta.embedded.block.astro,
51
+ contentName: source.ts,
52
+ patterns: [{ include: source.ts }],
53
+ },
54
+ ]
55
+
56
+ # Script Languages
57
+ # Default (JavaScript)
58
+ 'L:meta.script.astro - meta.lang - (meta source)':
59
+ patterns:
60
+ [
61
+ {
62
+ begin: '(?<=>)(?!</)',
63
+ end: '(?=</)',
64
+ name: meta.embedded.block.astro,
65
+ contentName: source.js,
66
+ patterns: [{ include: source.js }],
67
+ },
68
+ ]
69
+
70
+ # ----
71
+
72
+ # Style Languages
73
+ # Stylus | 'stylus' | 'source.stylus'
74
+ 'L:meta.style.astro meta.lang.stylus - (meta source)':
75
+ patterns:
76
+ [
77
+ {
78
+ begin: '(?<=>)(?!</)',
79
+ end: '(?=</)',
80
+ name: meta.embedded.block.astro,
81
+ contentName: source.stylus,
82
+ patterns: [{ include: source.stylus }],
83
+ },
84
+ ]
85
+
86
+ # Sass | 'sass' | 'source.sass'
87
+ 'L:meta.style.astro meta.lang.sass - (meta source)':
88
+ patterns:
89
+ [
90
+ {
91
+ begin: '(?<=>)(?!</)',
92
+ end: '(?=</)',
93
+ name: meta.embedded.block.astro,
94
+ contentName: source.sass,
95
+ patterns: [{ include: source.sass }],
96
+ },
97
+ ]
98
+
99
+ # CSS | 'css' | 'source.css'
100
+ 'L:meta.style.astro meta.lang.css - (meta source)':
101
+ patterns:
102
+ [
103
+ {
104
+ begin: '(?<=>)(?!</)',
105
+ end: '(?=</)',
106
+ name: meta.embedded.block.astro,
107
+ contentName: source.css,
108
+ patterns: [{ include: source.css }],
109
+ },
110
+ ]
111
+
112
+ # SCSS | 'scss' | 'source.css.scss'
113
+ 'L:meta.style.astro meta.lang.scss - (meta source)':
114
+ patterns:
115
+ [
116
+ {
117
+ begin: '(?<=>)(?!</)',
118
+ end: '(?=</)',
119
+ name: meta.embedded.block.astro,
120
+ contentName: source.css.scss,
121
+ patterns: [{ include: source.css.scss }],
122
+ },
123
+ ]
124
+
125
+ # Less | 'less' | 'source.css.less'
126
+ 'L:meta.style.astro meta.lang.less - (meta source)':
127
+ patterns:
128
+ [
129
+ {
130
+ begin: '(?<=>)(?!</)',
131
+ end: '(?=</)',
132
+ name: meta.embedded.block.astro,
133
+ contentName: source.css.less,
134
+ patterns: [{ include: source.css.less }],
135
+ },
136
+ ]
137
+
138
+ # PostCSS | 'postcss' | 'source.css.postcss'
139
+ 'L:meta.style.astro meta.lang.postcss - (meta source)':
140
+ patterns:
141
+ [
142
+ {
143
+ begin: '(?<=>)(?!</)',
144
+ end: '(?=</)',
145
+ name: meta.embedded.block.astro,
146
+ contentName: source.css.postcss,
147
+ patterns: [{ include: source.css.postcss }],
148
+ },
149
+ ]
150
+
151
+ # Default (CSS)
152
+ 'L:meta.style.astro - meta.lang - (meta source)':
153
+ patterns:
154
+ [
155
+ {
156
+ begin: '(?<=>)(?!</)',
157
+ end: '(?=</)',
158
+ name: meta.embedded.block.astro,
159
+ contentName: source.css,
160
+ patterns: [{ include: source.css }],
161
+ },
162
+ ]
163
+
164
+ # Start of grammar.
165
+ patterns:
166
+ - include: '#scope'
167
+ - include: '#frontmatter'
168
+
169
+ # Contains all of our patterns.
170
+ repository:
171
+ # ------------
172
+ # FRONTMATTER
173
+
174
+ # We use the `comment` scope for the triple dashes to get a "faded" look
175
+ frontmatter:
176
+ begin: \A(-{3})\s*$
177
+ end: (^|\G)(-{3})|\.{3}\s*$
178
+ beginCaptures:
179
+ 1: { name: comment }
180
+ endCaptures:
181
+ 2: { name: comment }
182
+ contentName: source.ts
183
+ patterns:
184
+ - include: source.ts
185
+
186
+ # -------
187
+ # SCOPE
188
+
189
+ # Used whenever a new scope is introduced, such as at the root level or within a content tag.
190
+ scope:
191
+ patterns:
192
+ - include: '#comments'
193
+ - include: '#tags'
194
+ - include: '#interpolation'
195
+ # Content text.
196
+ # This matches only inbetween all the nodes - nothing inside of them.
197
+ - begin: (?<=>|})
198
+ end: (?=<|{)
199
+ name: text.astro
200
+
201
+ # ----------
202
+ # COMMENTS
203
+
204
+ # Basic HTML comments.
205
+ comments:
206
+ begin: <!--
207
+ end: -->
208
+ captures:
209
+ 0: { name: punctuation.definition.comment.astro }
210
+ name: comment.block.astro
211
+ patterns:
212
+ # Validations
213
+ - { match: '\G-?>|<!--(?!>)|<!-(?=-->)|--!>', name: invalid.illegal.characters-not-allowed-here.astro }
214
+
215
+ # ------
216
+ # MISC
217
+
218
+ # Plain old interpolation between `{...}` blocks.
219
+ interpolation:
220
+ patterns:
221
+ - begin: \{
222
+ end: \}
223
+ beginCaptures: { 0: { name: punctuation.section.embedded.begin.astro } }
224
+ endCaptures: { 0: { name: punctuation.section.embedded.end.astro } }
225
+ contentName: meta.embedded.expression.astro source.tsx
226
+ patterns:
227
+ # Object literals - usually used within attributes.
228
+ - begin: \G\s*(?={)
229
+ end: (?<=})
230
+ patterns: [include: source.tsx#object-literal]
231
+ - include: source.tsx
232
+
233
+ # ------------
234
+ # ATTRIBUTES
235
+
236
+ attributes:
237
+ patterns:
238
+ - include: '#attributes-events'
239
+ - include: '#attributes-keyvalue'
240
+ - include: '#attributes-interpolated'
241
+
242
+ # HTML Events
243
+ # Set the source.js languages inside events attributes (ex: onclick) to get JS syntax highlighting in them just like VS Code has for .html files
244
+ attributes-events:
245
+ begin: (on(s(croll|t(orage|alled)|u(spend|bmit)|e(curitypolicyviolation|ek(ing|ed)|lect))|hashchange|c(hange|o(ntextmenu|py)|u(t|echange)|l(ick|ose)|an(cel|play(through)?))|t(imeupdate|oggle)|in(put|valid)|o(nline|ffline)|d(urationchange|r(op|ag(start|over|e(n(ter|d)|xit)|leave)?)|blclick)|un(handledrejection|load)|p(opstate|lay(ing)?|a(ste|use|ge(show|hide))|rogress)|e(nded|rror|mptied)|volumechange|key(down|up|press)|focus|w(heel|aiting)|l(oad(start|e(nd|d(data|metadata)))?|anguagechange)|a(uxclick|fterprint|bort)|r(e(s(ize|et)|jectionhandled)|atechange)|m(ouse(o(ut|ver)|down|up|enter|leave|move)|essage(error)?)|b(efore(unload|print)|lur)))(?![\\w:-])
246
+ beginCaptures:
247
+ 0:
248
+ patterns:
249
+ # Matches everything else.
250
+ - match: .*
251
+ name: entity.other.attribute-name.astro
252
+ end: (?=\s*+[^=\s])
253
+ name: 'meta.attribute.$1.astro'
254
+ patterns:
255
+ - begin: '='
256
+ beginCaptures: { 0: { name: punctuation.separator.key-value.astro } }
257
+ end: (?<=[^\s=])(?!\s*=)|(?=/?>)
258
+ patterns:
259
+ - begin: (?=[^\s=<>`/]|/(?!>))
260
+ end: (?!\G)
261
+ name: meta.embedded.line.js
262
+ patterns:
263
+ - match: (([^\s\"'=<>`/]|/(?!>))+)
264
+ name: string.unquoted.astro
265
+ captures:
266
+ - 0: { name: source.js }
267
+ - 1: { patterns: [{ include: source.js }] }
268
+ - begin: (['"])
269
+ end: \1
270
+ beginCaptures: { 0: { name: punctuation.definition.string.begin.astro } }
271
+ endCaptures: { 0: { name: punctuation.definition.string.end.astro } }
272
+ name: string.quoted.astro
273
+ patterns:
274
+ - match: ([^\n\"/]|/(?![/*]))+
275
+ captures: { 0: { patterns: [{ include: source.js }] } }
276
+ # Special handling for comments so they stay scoped inside the quotes
277
+ - begin: //
278
+ beginCaptures: { 0: { name: punctuation.definition.comment.js } }
279
+ end: (?=\")|\n
280
+ name: comment.line.double-slash.js
281
+ - begin: /\*
282
+ beginCaptures: { 0: { name: punctuation.definition.comment.begin.js } }
283
+ end: (?=\")|\*/
284
+ endCaptures: { 0: { name: punctuation.definition.comment.end.js } }
285
+ name: comment.block.js
286
+
287
+ # Interpolated shorthand attributes, like `{variable}` sitting by itself.
288
+ attributes-interpolated:
289
+ begin: (?<!:|=)\s*({)
290
+ end: (\})
291
+ contentName: meta.embedded.expression.astro source.tsx
292
+ patterns: [include: source.tsx]
293
+
294
+ # Matches attribute key-values. (and boolean attributes as well)
295
+ # e.g. `class="my-class"`, `required`
296
+ attributes-keyvalue:
297
+ begin: ([_@$[:alpha:]][:._\-$[:alnum:]]*)
298
+ beginCaptures:
299
+ 0:
300
+ patterns:
301
+ # Matches everything else.
302
+ - match: .*
303
+ name: entity.other.attribute-name.astro
304
+ end: (?=\s*+[^=\s])
305
+ name: 'meta.attribute.$1.astro'
306
+ patterns:
307
+ - begin: '='
308
+ beginCaptures: { 0: { name: punctuation.separator.key-value.astro } }
309
+ end: (?<=[^\s=])(?!\s*=)|(?=/?>)
310
+ patterns: [include: '#attributes-value']
311
+
312
+ # The value part of attribute key-values. e.g. `"my-class"` in `class="my-class"`
313
+ attributes-value:
314
+ patterns:
315
+ # No quotes - just an interpolation expression.
316
+ - include: '#interpolation'
317
+ # Unquoted strings.
318
+ - match: ([^\s"'=<>`/]|/(?!>))+
319
+ name: string.unquoted.astro
320
+ # Quoted strings.
321
+ - begin: (['"])
322
+ end: \1
323
+ beginCaptures: { 0: { name: punctuation.definition.string.begin.astro } }
324
+ endCaptures: { 0: { name: punctuation.definition.string.end.astro } }
325
+ name: string.quoted.astro
326
+ # Template literals
327
+ - begin: (`)
328
+ end: \1
329
+ name: string.template.astro
330
+ patterns:
331
+ - include: 'source.tsx#template-substitution-element'
332
+
333
+ # ------
334
+ # TAGS
335
+
336
+ # All tags together. Used whenever a new nested scope is introduced (and the root scope, of course).
337
+ tags:
338
+ patterns:
339
+ # The order is important here - void tags need to matched before block tags and end before start.
340
+ - include: '#tags-raw'
341
+ - include: '#tags-lang'
342
+ - include: '#tags-void'
343
+ - include: '#tags-general-end'
344
+ - include: '#tags-general-start'
345
+
346
+ # -- TAG COMPONENTS
347
+
348
+ # Scopes the `name` part in `<name>`.
349
+ tags-name:
350
+ patterns:
351
+ # Components.
352
+ - { match: '[A-Z][a-zA-Z0-9_]*', name: support.class.component.astro }
353
+ # Custom elements. (has a dash, but otherwise is a valid HTML element)
354
+ - { match: '[a-z][\w0-9:]*-[\w0-9:-]*', name: meta.tag.custom.astro entity.name.tag.astro }
355
+ # HTML elements.
356
+ - { match: '[a-z][\w0-9:-]*', name: entity.name.tag.astro }
357
+
358
+ # Attributes for tag start nodes. Meant to start immediately after the `<name` section.
359
+ tags-start-attributes:
360
+ begin: \G
361
+ end: (?=/?>)
362
+ name: meta.tag.start.astro
363
+ patterns: [include: '#attributes']
364
+
365
+ # Same as tags-start-attributes but slightly adjusted for special script/style/template tags.
366
+ tags-lang-start-attributes:
367
+ begin: \G
368
+ end: (?=/>)|>
369
+ endCaptures: { 0: { name: punctuation.definition.tag.end.astro } }
370
+ name: meta.tag.start.astro
371
+ patterns: [include: '#attributes']
372
+
373
+ # Matches the beginning (`<name`) section of a tag start node.
374
+ tags-start-node:
375
+ match: (<)([^/\s>/]*)
376
+ captures:
377
+ 1: { name: punctuation.definition.tag.begin.astro }
378
+ 2: { patterns: [include: '#tags-name'] }
379
+ name: meta.tag.start.astro
380
+
381
+ # Matches tag end nodes.
382
+ tags-end-node:
383
+ match: (</)(.*?)\s*(>)|(/>)
384
+ captures:
385
+ 1: { name: meta.tag.end.astro punctuation.definition.tag.begin.astro }
386
+ 2: { name: meta.tag.end.astro, patterns: [include: '#tags-name'] }
387
+ 3: { name: meta.tag.end.astro punctuation.definition.tag.end.astro }
388
+ 4: { name: meta.tag.start.astro punctuation.definition.tag.end.astro }
389
+
390
+ # -- TAG TYPES
391
+
392
+ # Tags marked as raw using `is:raw` - we need to handle those differently to make sure we properly set the language inside them
393
+ tags-raw:
394
+ begin: <([^/?!\s<>]+)(?=[^>]+is:raw).*?
395
+ beginCaptures:
396
+ 0: { patterns: [include: '#tags-start-node'] }
397
+ end: </\1\s*>|/>
398
+ endCaptures: { 0: { patterns: [include: '#tags-end-node'] } }
399
+ name: meta.scope.tag.$1.astro meta.raw.astro
400
+ contentName: source.unknown
401
+ patterns:
402
+ - include: '#tags-lang-start-attributes'
403
+
404
+ # Language tags - they are handled differently for the purposes of language injection.
405
+ tags-lang:
406
+ begin: <(script|style)
407
+ end: </\1\s*>|/>
408
+ beginCaptures: { 0: { patterns: [include: '#tags-start-node'] } }
409
+ endCaptures: { 0: { patterns: [include: '#tags-end-node'] } }
410
+ name: meta.scope.tag.$1.astro meta.$1.astro
411
+ patterns:
412
+ # Injecting into `meta.lang.ld+json` doesn't seem possible, so we set it to `meta.lang.json`
413
+ - begin: \G(?=\s*[^>]*?(type|lang)\s*=\s*(['"]|)(?:text\/)?(application\/ld\+json)\2)
414
+ end: (?=</|/>)
415
+ name: meta.lang.json.astro
416
+ patterns: [include: '#tags-lang-start-attributes']
417
+ # Treat 'module' as JavaScript
418
+ - begin: \G(?=\s*[^>]*?(type|lang)\s*=\s*(['"]|)(module)\2)
419
+ end: (?=</|/>)
420
+ name: meta.lang.javascript.astro
421
+ patterns: [include: '#tags-lang-start-attributes']
422
+ # Tags with a language specified.
423
+ - begin: \G(?=\s*[^>]*?(type|lang)\s*=\s*(['"]|)(?:text/|application/)?([\w\/+]+)\2)
424
+ end: (?=</|/>)
425
+ name: meta.lang.$3.astro
426
+ patterns: [include: '#tags-lang-start-attributes']
427
+ # Fallback to default language.
428
+ - include: '#tags-lang-start-attributes'
429
+
430
+ # Void element tags. They must be treated separately due to their lack of end nodes.
431
+ # A void element cannot be differentiated from other tags, unless you look at their name.
432
+ # This is because there is a specific list of void elements in HTML5. We use that to scope void elements.
433
+ # If we didn't, a void element would appear as an unclosed element to the grammar.
434
+ tags-void:
435
+ begin: (<)(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)(?=\s|/?>)
436
+ beginCaptures:
437
+ 1: { name: punctuation.definition.tag.begin.astro }
438
+ 2: { name: entity.name.tag.astro }
439
+ end: /?>
440
+ endCaptures: { 0: { name: punctuation.definition.tag.begin.astro } }
441
+ name: meta.tag.void.astro
442
+ patterns: [include: '#attributes']
443
+
444
+ # All other tags, including custom/special.astro tags.
445
+ # Split up into start and end because we don't need to preserve the name
446
+ # inside and because it makes whitespace matching logic more robust
447
+ tags-general-start:
448
+ begin: (<)([^/\s>/]*)
449
+ end: (/?>)
450
+ beginCaptures: { 0: { patterns: [include: '#tags-start-node'] } }
451
+ endCaptures:
452
+ 1: { name: meta.tag.start.astro punctuation.definition.tag.end.astro }
453
+ name: meta.scope.tag.$2.astro
454
+ patterns:
455
+ - include: '#tags-start-attributes'
456
+
457
+ tags-general-end:
458
+ begin: (</)([^/\s>]*)
459
+ end: (>)
460
+ beginCaptures:
461
+ 1: { name: meta.tag.end.astro punctuation.definition.tag.begin.astro }
462
+ 2: { name: meta.tag.end.astro, patterns: [include: '#tags-name'] }
463
+ endCaptures:
464
+ 1: { name: meta.tag.end.astro punctuation.definition.tag.end.astro }
465
+ name: meta.scope.tag.$2.astro