From 290504bb9d7c746aa2ecca71511d8278e21bc72a Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 31 Oct 2024 13:59:21 +0100 Subject: [PATCH] Add lang/type completion support 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 https://github.com/sublimehq/Packages/pull/4061 --- HTML (CoffeeScript).sublime-syntax | 27 ++++++++++++++++++-------- Script Lang Values.sublime-completions | 10 ++++++++++ Script Type Values.sublime-completions | 25 ++++++++++++++++++++++++ tests/syntax_test_scope.html | 27 ++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 Script Lang Values.sublime-completions create mode 100644 Script Type Values.sublime-completions diff --git a/HTML (CoffeeScript).sublime-syntax b/HTML (CoffeeScript).sublime-syntax index 92cf857..2db1d0d 100644 --- a/HTML (CoffeeScript).sublime-syntax +++ b/HTML (CoffeeScript).sublime-syntax @@ -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 @@ -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 @@ -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}}? ) diff --git a/Script Lang Values.sublime-completions b/Script Lang Values.sublime-completions new file mode 100644 index 0000000..90e5f70 --- /dev/null +++ b/Script Lang Values.sublime-completions @@ -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" + } + ] +} \ No newline at end of file diff --git a/Script Type Values.sublime-completions b/Script Type Values.sublime-completions new file mode 100644 index 0000000..c32fa95 --- /dev/null +++ b/Script Type Values.sublime-completions @@ -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" + } + ] +} \ No newline at end of file diff --git a/tests/syntax_test_scope.html b/tests/syntax_test_scope.html index a7f67e0..fec4d33 100644 --- a/tests/syntax_test_scope.html +++ b/tests/syntax_test_scope.html @@ -28,6 +28,7 @@ +# <- 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