Skip to content

Commit

Permalink
Unique type attribute scope
Browse files Browse the repository at this point in the history
This commit scopes `type` attributes special to enable static type value
completions and adjusts some tests to maintain compatibility with older
ST builds.

Related with sublimehq/Packages#4061
  • Loading branch information
deathaxe committed Nov 2, 2024
1 parent c2cc2f6 commit 2d345ae
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
22 changes: 20 additions & 2 deletions Syntaxes/HTML (Astro).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,41 @@ contexts:
- meta_scope: meta.attribute-with-value.lang.html
- include: immediately-pop

script-type-attribute:
# required until https://github.com/sublimehq/Packages/pull/4061
- match: (?i:type){{attribute_name_break}}
scope: meta.attribute-with-value.type.html entity.other.attribute-name.html
set: script-type-attribute-assignment

script-type-attribute-assignment:
- meta_include_prototype: false
- meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html
- meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.type.html
- match: =
scope: punctuation.separator.key-value.html
set: script-type-attribute-value
- match: (?=\S)
set: script-typescript

script-type-attribute-value:
# required until https://github.com/sublimehq/Packages/pull/4061
- meta_include_prototype: false
- meta_scope: meta.tag.script.begin.html meta.attribute-with-value.type.html
- include: script-type-decider

script-type-decider:
- meta_prepend: true
- match: (?=>|''|"")
set:
- script-javascript
- tag-generic-attribute-meta
- tag-type-attribute-meta
- tag-generic-attribute-value

tag-type-attribute-meta:
# required until https://github.com/sublimehq/Packages/pull/4061
- meta_include_prototype: false
- meta_scope: meta.attribute-with-value.type.html
- include: immediately-pop

script-typescript:
- meta_scope: meta.tag.script.begin.html
- match: '>'
Expand Down
37 changes: 32 additions & 5 deletions tests/syntax_test_script.astro
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,35 @@


<script type="text/javascript"> <!--
// ^^^^^^^^ meta.tag - meta.attribute-with-value - source.js
// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value - source.js
// ^ meta.tag - meta.attribute-with-value - source.js
// ^^^^^ - meta.tag - source.js
// ^^^^^^ entity.name.tag
// ^^^^ entity.other.attribute-name.html
// ^ punctuation.separator.key-value.html
// ^^^^^^^^^^^^^^^^^ string.quoted.double.html
// ^^^^ comment.block.html punctuation.definition.comment.begin.html

var foo = 100;
// <- source.js.embedded.html - source.js source.js

(a --> b);
// ^^^ source.js.embedded.html keyword.operator - comment

--> </script>
// ^^^^^^^^^^^^^^ - source.js
// ^ - meta.tag - comment
// ^^^^^^^^^ meta.tag
// ^ - meta.tag
// ^^^ comment.block.html punctuation.definition.comment.end.html
// ^^ punctuation.definition.tag.begin.html
// ^^^^^^ entity.name.tag.script.html
// ^ punctuation.definition.tag.end.html

<script type="text/typescript"> <!--
// ^^^^^^^^ meta.tag - meta.attribute-with-value - source.ts
// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value - source.ts
// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.type.html - meta.attribute-with-value meta.attribute-with-value - source.ts
// ^ meta.tag - meta.attribute-with-value - source.ts
// ^^^^^ - meta.tag - source.ts
// ^^^^^^ entity.name.tag
Expand All @@ -101,10 +128,10 @@
// ^ source.js.embedded.html

var foo = 100;
// <- source.js.embedded.html - source.ts source.ts
// <- source.ts.embedded.html - source.ts source.ts

(a --> b);
// ^^^ source.js.embedded.html keyword.operator - comment
// ^^^ source.ts.embedded.html keyword.operator - comment

--> </script>
// ^ source.js.embedded.html - source.ts source.ts
Expand All @@ -120,10 +147,10 @@

<script
type
// ^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value
// ^^^^ meta.tag meta.attribute-with-value.type.html - meta.attribute-with-value meta.attribute-with-value
=
application/jAvAsCrIpT>
// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value
// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value
var foo = 100;
// <- source.ts.embedded.html - source.ts source.ts
// ^^^^^^^^^^^^^^^^ source.ts.embedded.html - source.ts source.ts
Expand Down
6 changes: 3 additions & 3 deletions tests/syntax_test_style.astro
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

<style type="text/css"> <!--
// ^^^^^^^ meta.tag - meta.attribute-with-value - source.css
// ^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value - source.css
// ^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value - source.css
// ^ meta.tag - meta.attribute-with-value - source.css
// ^^^^^ - meta.tag - source.css
// ^^^^^ entity.name.tag
Expand All @@ -119,10 +119,10 @@

<style
type
// ^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value
// ^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value
=
tExT/cSs>
// ^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value
// ^^^^^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value

h1 {}
// <- source.css.embedded.html - source.css source.css
Expand Down

0 comments on commit 2d345ae

Please sign in to comment.