Skip to content

Commit

Permalink
Add lang/type completion support
Browse files Browse the repository at this point in the history
This commit...

1. adds `language` to list of supported tag attributes
   used to detect script language.
2. adds dedicated meta scopes for `lang` and `type` attributes
3. adds completions for those values.

Follows sublimehq/Packages#4061
  • Loading branch information
deathaxe committed Oct 31, 2024
1 parent 54fa545 commit 290504b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
27 changes: 19 additions & 8 deletions HTML (CoffeeScript).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ contexts:

script-common:
- meta_prepend: true
- match: (?i:lang){{attribute_name_break}}
scope: meta.attribute-with-value.html entity.other.attribute-name.html
- match: (?i:lang(?:uage)?){{attribute_name_break}}
scope: meta.attribute-with-value.lang.html entity.other.attribute-name.html
set: script-lang-attribute-assignment

script-lang-attribute-assignment:
- 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.lang.html
- match: =
scope: punctuation.separator.key-value.html
set: script-lang-attribute-value
Expand All @@ -28,26 +28,37 @@ contexts:

script-lang-attribute-value:
- meta_include_prototype: false
- meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html
- meta_scope: meta.tag.script.begin.html meta.attribute-with-value.lang.html
- match: (?=(?i:coffee{{unquoted_attribute_break}}|'coffee'|"coffee"))
set:
- script-coffee
- tag-generic-attribute-meta
- tag-lang-attribute-meta
- tag-generic-attribute-value
- match: (?=\S)
set:
- script-javascript
- tag-generic-attribute-meta
- tag-lang-attribute-meta
- tag-generic-attribute-value

tag-lang-attribute-meta:
- meta_include_prototype: false
- meta_scope: meta.attribute-with-value.lang.html
- include: immediately-pop

script-type-decider:
- meta_prepend: true
- match: (?={{coffee_mime_type}}{{unquoted_attribute_break}}|'{{coffee_mime_type}}'|"{{coffee_mime_type}}")
set:
- script-coffee
- tag-generic-attribute-meta
- tag-type-attribute-meta
- tag-generic-attribute-value

tag-type-attribute-meta:
# required until ST4184
- meta_include_prototype: false
- meta_scope: meta.attribute-with-value.type.html
- include: immediately-pop

script-coffee:
- meta_include_prototype: false
- meta_scope: meta.tag.script.begin.html
Expand Down Expand Up @@ -86,4 +97,4 @@ contexts:
variables:

coffee_mime_type: |-
(?xi: (?: (?: application |text ) / coffee(?:script)? ) {{mime_type_parameters}}? )
(?xi: (?: (?: application | text ) / coffee(?:script)? ) {{mime_type_parameters}}? )
10 changes: 10 additions & 0 deletions Script Lang Values.sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"scope": "text.html meta.tag.script meta.attribute-with-value.lang",
"completions": [
{
"trigger": "coffee",
"kind": ["type", "t", "Language Type"],
"details": "CoffeeScript"
}
]
}
25 changes: 25 additions & 0 deletions Script Type Values.sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"scope": "text.html meta.tag.script meta.attribute-with-value.type",
"completions": [
{
"trigger": "application/coffee",
"kind": ["type", "t", "Mime Type"],
"details": "CoffeeScript"
},
{
"trigger": "application/coffeescript",
"kind": ["type", "t", "Mime Type"],
"details": "CoffeeScript"
},
{
"trigger": "text/coffee",
"kind": ["type", "t", "Mime Type"],
"details": "CoffeeScript"
},
{
"trigger": "text/coffeescript",
"kind": ["type", "t", "Mime Type"],
"details": "CoffeeScript"
}
]
}
27 changes: 27 additions & 0 deletions tests/syntax_test_scope.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<script lang="coffee">
# <- meta.tag.script.begin.html punctuation.definition.tag.begin.html
#^^^^^^^^^^^^^^^^^^^^^ meta.tag.script.begin.html
# ^^^^^^^^^^^^^ meta.attribute-with-value.lang.html
#^^^^^^ entity.name.tag.script.html
# ^^^^ entity.other.attribute-name.html
# ^ punctuation.separator.key-value.html
Expand All @@ -49,3 +50,29 @@
#^ punctuation.definition.tag.begin.html
# ^^^^^^ entity.name.tag.script.html
# ^ punctuation.definition.tag.end.html

<script language="coffee">
# <- meta.tag.script.begin.html punctuation.definition.tag.begin.html
#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.script.begin.html
# ^^^^^^^^^^^^^^^^^ meta.attribute-with-value.lang.html
#^^^^^^ entity.name.tag.script.html
# ^^^^^^^^ entity.other.attribute-name.html
# ^ punctuation.separator.key-value.html
# ^^^^^^^^ meta.string.html string.quoted.double.html
# ^ punctuation.definition.tag.end.html
class extends parentClass
# <- source.coffee.embedded.html meta.class.coffee keyword.declaration.class.coffee
#^^^^^^^^^^^^^^^^^^^^^^^^ source.coffee.embedded.html meta.class
#^^^^ keyword.declaration.class.coffee
# ^^^^^^^ storage.modifier.extends.coffee
# ^^^^^^^^^^^ entity.other.inherited-class.coffee
constructor: ->
return
# <- source.coffee.embedded.html
# ^^^^^^ source.coffee.embedded.html keyword.control.flow.coffee
</script>
# <- meta.tag.script.end.html punctuation.definition.tag.begin.html
#^^^^^^^^ meta.tag.script.end.html
#^ punctuation.definition.tag.begin.html
# ^^^^^^ entity.name.tag.script.html
# ^ punctuation.definition.tag.end.html

0 comments on commit 290504b

Please sign in to comment.