diff --git a/.changeset/selfish-icons-breathe.md b/.changeset/selfish-icons-breathe.md
new file mode 100644
index 00000000..02905784
--- /dev/null
+++ b/.changeset/selfish-icons-breathe.md
@@ -0,0 +1,5 @@
+---
+'astro-vscode': patch
+---
+
+Improved syntax highlighting, auto-indentation and auto-closing
diff --git a/packages/vscode/languages/astro-language-configuration.json b/packages/vscode/languages/astro-language-configuration.json
index 5e761af0..99ad2474 100644
--- a/packages/vscode/languages/astro-language-configuration.json
+++ b/packages/vscode/languages/astro-language-configuration.json
@@ -3,11 +3,9 @@
"blockComment": [""]
},
"brackets": [
- ["---", "---"],
[""],
["<", ">"],
- ["{", "}"],
- ["(", ")"]
+ ["{", "}"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}" },
@@ -16,13 +14,15 @@
{ "open": "'", "close": "'" },
{ "open": "\"", "close": "\"" },
{ "open": "`", "close": "`" },
- { "open": "", "notIn": ["comment", "string"] },
+ { "open": "{/*", "close": " */}", "notIn": ["comment", "string"] },
+ { "open": "", "notIn": ["comment", "string"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"autoCloseBefore": ";:.,=}])>` \n\t",
"surroundingPairs": [
{ "open": "'", "close": "'" },
{ "open": "\"", "close": "\"" },
+ { "open": "`", "close": "`" },
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
@@ -33,5 +33,36 @@
"start": "^\\s*",
"end": "^\\s*"
}
+ },
+ "wordPattern": {
+ "pattern": "([^\\-\\s]+-[^\\-\\s]+)|(-?\\d*\\.\\d\\w*)|([^\\`\\~\\-\\!\\@\\$\\^\\&\\*\\(\\)\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:'\"\\,\\.\\<\\>\\/\\s]+)"
+ },
+ "onEnterRules": [
+ {
+ "beforeText": {
+ "pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\\w][_:\\w\\-.\\d]*)([^/>]*(?!/)>)[^<]*$",
+ "flags": "i"
+ },
+ "afterText": {
+ "pattern": "^<\\/([_:\\w][_:\\w-.\\d]*)\\s*>$",
+ "flags": "i"
+ },
+ "action": {
+ "indent": "indentOutdent"
+ }
+ },
+ {
+ "beforeText": {
+ "pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\\w][_:\\w\\-.\\d]*)([^/>]*(?!/)>)[^<]*$",
+ "flags": "i"
+ },
+ "action": {
+ "indent": "indent"
+ }
+ }
+ ],
+ "indentationRules": {
+ "increaseIndentPattern": "<(?!\\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr)\\b|[^>]*\\/>)([-_\\.A-Za-z0-9]+)(?=\\s|>)\\b[^>]*>(?!.*<\\/\\1>)|)|\\{[^}\"']*$",
+ "decreaseIndentPattern": "^\\s*(<\\/(?!html)[-_\\.A-Za-z0-9]+\\b[^>]*>|-->|\\})"
}
}
diff --git a/packages/vscode/package.json b/packages/vscode/package.json
index a30d58cd..f8dedf36 100644
--- a/packages/vscode/package.json
+++ b/packages/vscode/package.json
@@ -16,7 +16,10 @@
"vscode:prepublish": "yarn build",
"build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
"dev": "astro-scripts dev \"src/**/*.ts\"",
- "test": "node ./test/runTest.js"
+ "test": "yarn run test:vscode && yarn run test:grammar",
+ "test:vscode": "node ./test/runTest.js",
+ "test:grammar": "node ./test/grammar/test.mjs",
+ "update-grammar-snapshots": "node ./test/grammar/test.mjs --updateSnapshot"
},
"engines": {
"vscode": "^1.67.0"
@@ -28,7 +31,8 @@
"dependencies": {
"@astrojs/language-server": "0.19.0",
"@astrojs/ts-plugin": "0.2.1",
- "vscode-languageclient": "^8.0.1"
+ "vscode-languageclient": "^8.0.1",
+ "vscode-tmgrammar-test": "^0.1.1"
},
"devDependencies": {
"@types/glob": "^7.2.0",
@@ -252,6 +256,7 @@
"source.stylus": "stylus",
"source.js": "javascript",
"source.ts": "typescript",
+ "source.json": "json",
"source.tsx": "typescriptreact"
}
},
diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json
index e19e4346..c93486dd 100644
--- a/packages/vscode/syntaxes/astro.tmLanguage.json
+++ b/packages/vscode/syntaxes/astro.tmLanguage.json
@@ -68,25 +68,64 @@
]
},
"astro:component": {
- "name": "meta.tag.component.astro",
- "begin": "(?)([$A-Z_][^/?!\\s<>]*|[^/?!\\s<>.]+\\.[^/?!\\s<>]+)\\b",
- "beginCaptures": {
- "1": {
- "name": "punctuation.definition.tag.begin.astro"
- },
- "2": {
- "name": "entity.name.tag.astro support.class.component.astro"
- }
- },
- "end": "(/?>)",
- "endCaptures": {
- "1": {
- "name": "punctuation.definition.tag.end.astro"
- }
- },
"patterns": [
{
- "include": "#astro:attribute"
+ "name": "meta.tag.component.astro astro.component.raw",
+ "begin": "(<)([$A-Z_][^/?!\\s<>]*|[^/?!\\s<>.]+\\.[^/?!\\s<>]+)(.+is:raw.*?)(>)",
+ "end": "()([$A-Z_][^/?!\\s<>]*|[^/?!\\s<>.]+\\.[^/?!\\s<>]+)(?=\\s|/?>)(>)",
+ "beginCaptures": {
+ "1": {
+ "name": "punctuation.definition.tag.begin.astro"
+ },
+ "2": {
+ "name": "entity.name.tag.astro support.class.component.astro"
+ },
+ "3": {
+ "patterns": [
+ {
+ "include": "#astro:attribute"
+ }
+ ]
+ },
+ "4": {
+ "name": "punctuation.definition.tag.end.astro"
+ }
+ },
+ "endCaptures": {
+ "1": {
+ "name": "punctuation.definition.tag.begin.astro"
+ },
+ "2": {
+ "name": "entity.name.tag.astro support.class.component.astro"
+ },
+ "3": {
+ "name": "punctuation.definition.tag.end.astro"
+ }
+ },
+ "contentName": "source.unknown"
+ },
+ {
+ "name": "meta.tag.component.astro",
+ "begin": "(?)([$A-Z_][^/?!\\s<>]*|[^/?!\\s<>.]+\\.[^/?!\\s<>]+)\\b",
+ "beginCaptures": {
+ "1": {
+ "name": "punctuation.definition.tag.begin.astro"
+ },
+ "2": {
+ "name": "entity.name.tag.astro support.class.component.astro"
+ }
+ },
+ "end": "(/?>)",
+ "endCaptures": {
+ "1": {
+ "name": "punctuation.definition.tag.end.astro"
+ }
+ },
+ "patterns": [
+ {
+ "include": "#astro:attribute"
+ }
+ ]
}
]
},
@@ -131,6 +170,47 @@
}
},
"patterns": [
+ {
+ "comment": "Treat script tag with application/ld+json as JSON. This needs to be higher than is:raw since it's a very possible situation to have is:raw on a JSON script tag",
+ "begin": "\\G(?=\\s*[^>]*?type\\s*=\\s*(['\"]|)(?i:application/ld\\+json)\\1)",
+ "end": "(?=|/>)",
+ "patterns": [
+ {
+ "begin": "(?<=>)(?!)",
+ "end": "(?=)",
+ "contentName": "source.json",
+ "patterns": [{ "include": "source.json" }]
+ },
+ { "include": "#html:tag-attributes" }
+ ]
+ },
+ {
+ "comment": "Treat script tag with JS-compatible types as JS",
+ "begin": "\\G(?=\\s*[^>]*?type\\s*=\\s*(['\"]|)(?i:module|(?:text/javascript|text/partytown|application/node|application/javascript))\\1)",
+ "end": "(?=|/>)",
+ "patterns": [
+ {
+ "begin": "(?<=>)(?!)",
+ "end": "(?=)",
+ "contentName": "source.js",
+ "patterns": [{ "include": "source.js" }]
+ },
+ { "include": "#html:tag-attributes" }
+ ]
+ },
+ {
+ "comment": "Treat anything with an unknown type as unknown",
+ "begin": "\\G(?=\\s*[^>]*?type\\s*=\\s*(['\"]|)\\1)",
+ "end": "(?=|/>)",
+ "patterns": [
+ {
+ "begin": "(?<=>)(?!)",
+ "end": "(?=)",
+ "name": "source.unknown"
+ },
+ { "include": "#html:tag-attributes" }
+ ]
+ },
{
"begin": "\\G(?=\\s*[^>]*?lang\\s*=\\s*(['\"]|)(?i:jsx?|javascript)\\1)",
"end": "(?=|/>)",
@@ -367,6 +447,41 @@
},
"html:element": {
"patterns": [
+ {
+ "name": "astro.element.raw",
+ "begin": "(<)([^/?!\\s<>]+)(.+is:raw.*?)(>)",
+ "end": "()([^/?!\\s<>]+)(?=\\s|/?>)(>)",
+ "beginCaptures": {
+ "1": {
+ "name": "punctuation.definition.tag.begin.html"
+ },
+ "2": {
+ "name": "entity.name.tag.html"
+ },
+ "3": {
+ "patterns": [
+ {
+ "include": "#astro:attribute"
+ }
+ ]
+ },
+ "4": {
+ "name": "punctuation.definition.tag.end.html"
+ }
+ },
+ "endCaptures": {
+ "1": {
+ "name": "punctuation.definition.tag.begin.html"
+ },
+ "2": {
+ "name": "entity.name.tag.html"
+ },
+ "3": {
+ "name": "punctuation.definition.tag.end.html"
+ }
+ },
+ "contentName": "source.unknown"
+ },
{
"name": "meta.tag.any.$2.start.html",
"begin": "(<)([^/?!\\s<>]+)(?=\\s|/?>)",
@@ -445,16 +560,16 @@
"begin": "\\{",
"beginCaptures": {
"0": {
- "name": "punctuation.definition.generic.begin.html"
+ "name": "punctuation.section.embedded.begin.tsx"
}
},
"end": "\\}",
"endCaptures": {
"0": {
- "name": "punctuation.definition.generic.end.html"
+ "name": "punctuation.section.embedded.end.tsx"
}
},
- "name": "expression.embbeded.astro",
+ "name": "expression.embedded.astro",
"contentName": "source.tsx",
"patterns": [
{
@@ -500,10 +615,11 @@
]
},
"frontmatter": {
+ "comment": "The frontmatter is treated as comments in order to get the \"faded\" look",
"begin": "\\A(-{3})\\s*$",
"beginCaptures": {
"1": {
- "name": "comment.block.html"
+ "name": "comment"
}
},
"contentName": "source.ts",
@@ -515,7 +631,7 @@
"end": "(^|\\G)(-{3})|\\.{3}\\s*$",
"endCaptures": {
"2": {
- "name": "comment.block.html"
+ "name": "comment"
}
}
},
diff --git a/packages/vscode/test/grammar/README.md b/packages/vscode/test/grammar/README.md
new file mode 100644
index 00000000..7ef36734
--- /dev/null
+++ b/packages/vscode/test/grammar/README.md
@@ -0,0 +1,5 @@
+# Testing syntax files
+
+This is a testing setup powered by [vscode-tmgrammar-test](https://github.com/PanAeon/vscode-tmgrammar-test) intended to test our `astro.tmLanguage.json` file to make sure it properly handle `.astro` files. To run it, simply run the `test:grammar` npm script from the repo
+
+[Snapshots](https://github.com/PanAeon/vscode-tmgrammar-test#snapshot-tests) can be updated using the `update-grammar-snapshots` npm script, however, unless your changes affect the currently present snapshots, you should always make sure to run the tests (`yarn run test:grammar`) before updating the snapshots, to make sure your changes do not introduce regressions
diff --git a/packages/vscode/test/grammar/dummy/css.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/css.tmLanguage-dummy.json
new file mode 100644
index 00000000..5e6df8ec
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/css.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy CSS TextMate grammar for use in testing",
+ "scopeName": "source.css"
+}
diff --git a/packages/vscode/test/grammar/dummy/html.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/html.tmLanguage-dummy.json
new file mode 100644
index 00000000..633cbb58
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/html.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy HTML TextMate grammar for use in testing",
+ "scopeName": "text.html"
+}
diff --git a/packages/vscode/test/grammar/dummy/js.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/js.tmLanguage-dummy.json
new file mode 100644
index 00000000..ac9f4a19
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/js.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy JS TextMate grammar for use in testing",
+ "scopeName": "source.js"
+}
diff --git a/packages/vscode/test/grammar/dummy/json.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/json.tmLanguage-dummy.json
new file mode 100644
index 00000000..293c33fd
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/json.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy JSON TextMate grammar for use in testing",
+ "scopeName": "source.json"
+}
diff --git a/packages/vscode/test/grammar/dummy/less.tsLanguage-dummy.json b/packages/vscode/test/grammar/dummy/less.tsLanguage-dummy.json
new file mode 100644
index 00000000..e8119462
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/less.tsLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy Less TextMate grammar for use in testing",
+ "scopeName": "source.css.less"
+}
diff --git a/packages/vscode/test/grammar/dummy/markdown.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/markdown.tmLanguage-dummy.json
new file mode 100644
index 00000000..83a66252
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/markdown.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy Markdown TextMate grammar for use in testing",
+ "scopeName": "text.html.markdown"
+}
diff --git a/packages/vscode/test/grammar/dummy/sass.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/sass.tmLanguage-dummy.json
new file mode 100644
index 00000000..ae0671ad
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/sass.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy Sass TextMate grammar for use in testing",
+ "scopeName": "source.sass"
+}
diff --git a/packages/vscode/test/grammar/dummy/scss.tsLanguage-dummy.json b/packages/vscode/test/grammar/dummy/scss.tsLanguage-dummy.json
new file mode 100644
index 00000000..197230d2
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/scss.tsLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy Scss TextMate grammar for use in testing",
+ "scopeName": "source.css.scss"
+}
diff --git a/packages/vscode/test/grammar/dummy/stylus.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/stylus.tmLanguage-dummy.json
new file mode 100644
index 00000000..995e0701
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/stylus.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy Stylus TextMate grammar for use in testing",
+ "scopeName": "source.stylus"
+}
diff --git a/packages/vscode/test/grammar/dummy/ts.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/ts.tmLanguage-dummy.json
new file mode 100644
index 00000000..1a208803
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/ts.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy TS TextMate grammar for use in testing",
+ "scopeName": "source.ts"
+}
diff --git a/packages/vscode/test/grammar/dummy/tsx.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/tsx.tmLanguage-dummy.json
new file mode 100644
index 00000000..2918d4c1
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/tsx.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy TSX TextMate grammar for use in testing",
+ "scopeName": "source.tsx"
+}
diff --git a/packages/vscode/test/grammar/dummy/unknown.tmLanguage-dummy.json b/packages/vscode/test/grammar/dummy/unknown.tmLanguage-dummy.json
new file mode 100644
index 00000000..4f2f5007
--- /dev/null
+++ b/packages/vscode/test/grammar/dummy/unknown.tmLanguage-dummy.json
@@ -0,0 +1,4 @@
+{
+ "comment": "Dummy Unknown TextMate grammar for use in testing",
+ "scopeName": "source.unknown"
+}
diff --git a/packages/vscode/test/grammar/fixtures/components/component.astro b/packages/vscode/test/grammar/fixtures/components/component.astro
new file mode 100644
index 00000000..dea96841
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/components/component.astro
@@ -0,0 +1,3 @@
+
+
+
diff --git a/packages/vscode/test/grammar/fixtures/components/component.astro.snap b/packages/vscode/test/grammar/fixtures/components/component.astro.snap
new file mode 100644
index 00000000..82c75c65
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/components/component.astro.snap
@@ -0,0 +1,17 @@
+>
+#^ source.astro meta.tag.component.astro punctuation.definition.tag.begin.astro
+# ^^^^^^^^^ source.astro meta.tag.component.astro entity.name.tag.astro support.class.component.astro
+# ^ source.astro meta.tag.component.astro punctuation.definition.tag.end.astro
+>
+#^ source.astro
+# ^ source.astro meta.tag.any.div.start.html punctuation.definition.tag.begin.html
+# ^^^ source.astro meta.tag.any.div.start.html entity.name.tag.html
+# ^ source.astro meta.tag.any.div.start.html punctuation.definition.tag.end.html
+# ^^ source.astro meta.tag.any.div.end.html punctuation.definition.tag.begin.html
+# ^^^ source.astro meta.tag.any.div.end.html entity.name.tag.html
+# ^ source.astro meta.tag.any.div.end.html punctuation.definition.tag.end.html
+>
+#^^ source.astro meta.tag.component.astro punctuation.definition.tag.begin.astro
+# ^^^^^^^^^ source.astro meta.tag.component.astro entity.name.tag.astro support.class.component.astro
+# ^ source.astro meta.tag.component.astro punctuation.definition.tag.end.astro
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/markdown/markdown.astro b/packages/vscode/test/grammar/fixtures/markdown/markdown.astro
new file mode 100644
index 00000000..0441f266
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/markdown/markdown.astro
@@ -0,0 +1,7 @@
+---
+ import { Markdown } from "astro/components"
+---
+
+
+ # Title
+
diff --git a/packages/vscode/test/grammar/fixtures/markdown/markdown.astro.snap b/packages/vscode/test/grammar/fixtures/markdown/markdown.astro.snap
new file mode 100644
index 00000000..1a32a48c
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/markdown/markdown.astro.snap
@@ -0,0 +1,18 @@
+>---
+#^^^ source.astro comment
+> import { Markdown } from "astro/components"
+#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.ts
+>---
+#^^^ source.astro comment
+>
+>
+#^ source.astro punctuation.definition.tag.begin.astro
+# ^^^^^^^^ source.astro entity.name.tag.astro support.class.component.astro
+# ^ source.astro punctuation.definition.tag.end.html
+> # Title
+#^^^^^^^^^ source.astro text.html.markdown
+>
+#^^ source.astro punctuation.definition.tag.begin.astro
+# ^^^^^^^^ source.astro entity.name.tag.astro support.class.component.astro
+# ^ source.astro punctuation.definition.tag.end.astro
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/raw/israw.astro b/packages/vscode/test/grammar/fixtures/raw/israw.astro
new file mode 100644
index 00000000..d0b910e3
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/raw/israw.astro
@@ -0,0 +1,15 @@
+
+ Hello
+
+
+
+ Hello
+
+
+
+ Hello
+
+
+
+ Hello
+
diff --git a/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap b/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap
new file mode 100644
index 00000000..43f870fc
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap
@@ -0,0 +1,68 @@
+>
+#^ source.astro astro.element.raw punctuation.definition.tag.begin.html
+# ^^^ source.astro astro.element.raw entity.name.tag.html
+# ^ source.astro astro.element.raw
+# ^^^^^^ source.astro astro.element.raw meta.attribute.is:raw.html entity.other.attribute-name.html
+# ^ source.astro astro.element.raw punctuation.definition.tag.end.html
+> Hello
+#^^^^^^^ source.astro astro.element.raw source.unknown
+>
+#^^ source.astro astro.element.raw punctuation.definition.tag.begin.html
+# ^^^ source.astro astro.element.raw entity.name.tag.html
+# ^ source.astro astro.element.raw punctuation.definition.tag.end.html
+>
+>
+#^ source.astro astro.element.raw punctuation.definition.tag.begin.html
+# ^^^ source.astro astro.element.raw entity.name.tag.html
+# ^ source.astro astro.element.raw
+# ^^^^^^^^^ source.astro astro.element.raw meta.attribute.aria-busy.html entity.other.attribute-name.html
+# ^ source.astro astro.element.raw
+# ^^^^^ source.astro astro.element.raw meta.attribute.class.html entity.other.attribute-name.html
+# ^ source.astro astro.element.raw meta.attribute.class.html punctuation.separator.key-value.html
+# ^ source.astro astro.element.raw string.quoted.double.html punctuation.definition.string.begin.html
+# ^^^^^ source.astro astro.element.raw string.quoted.double.html
+# ^ source.astro astro.element.raw string.quoted.double.html punctuation.definition.string.end.html
+# ^ source.astro astro.element.raw
+# ^^^^^^ source.astro astro.element.raw meta.attribute.is:raw.html entity.other.attribute-name.html
+# ^ source.astro astro.element.raw punctuation.definition.tag.end.html
+> Hello
+#^^^^^^^ source.astro astro.element.raw source.unknown
+>
+#^^ source.astro astro.element.raw punctuation.definition.tag.begin.html
+# ^^^ source.astro astro.element.raw entity.name.tag.html
+# ^ source.astro astro.element.raw punctuation.definition.tag.end.html
+>
+>
+#^ source.astro astro.element.raw punctuation.definition.tag.begin.html
+# ^^^ source.astro astro.element.raw entity.name.tag.html
+# ^ source.astro astro.element.raw
+# ^^^^^ source.astro astro.element.raw meta.attribute.class.html entity.other.attribute-name.html
+# ^ source.astro astro.element.raw meta.attribute.class.html punctuation.separator.key-value.html
+# ^ source.astro astro.element.raw string.quoted.double.html punctuation.definition.string.begin.html
+# ^^^^^ source.astro astro.element.raw string.quoted.double.html
+# ^ source.astro astro.element.raw string.quoted.double.html punctuation.definition.string.end.html
+# ^ source.astro astro.element.raw
+# ^^^^^^ source.astro astro.element.raw meta.attribute.is:raw.html entity.other.attribute-name.html
+# ^ source.astro astro.element.raw
+# ^^^^^^^^^ source.astro astro.element.raw meta.attribute.aria-busy.html entity.other.attribute-name.html
+# ^ source.astro astro.element.raw punctuation.definition.tag.end.html
+> Hello
+#^^^^^^^ source.astro astro.element.raw source.unknown
+>
+#^^ source.astro astro.element.raw punctuation.definition.tag.begin.html
+# ^^^ source.astro astro.element.raw entity.name.tag.html
+# ^ source.astro astro.element.raw punctuation.definition.tag.end.html
+>
+>
+#^ source.astro meta.tag.component.astro astro.component.raw punctuation.definition.tag.begin.astro
+# ^^^^^^^^^ source.astro meta.tag.component.astro astro.component.raw entity.name.tag.astro support.class.component.astro
+# ^ source.astro meta.tag.component.astro astro.component.raw
+# ^^^^^^ source.astro meta.tag.component.astro astro.component.raw meta.attribute.is:raw.html entity.other.attribute-name.html
+# ^ source.astro meta.tag.component.astro astro.component.raw punctuation.definition.tag.end.astro
+> Hello
+#^^^^^^^ source.astro meta.tag.component.astro astro.component.raw source.unknown
+>
+#^^ source.astro meta.tag.component.astro astro.component.raw punctuation.definition.tag.begin.astro
+# ^^^^^^^^^ source.astro meta.tag.component.astro astro.component.raw entity.name.tag.astro support.class.component.astro
+# ^ source.astro meta.tag.component.astro astro.component.raw punctuation.definition.tag.end.astro
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/script/israw.astro b/packages/vscode/test/grammar/fixtures/script/israw.astro
new file mode 100644
index 00000000..dbb0caff
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/israw.astro
@@ -0,0 +1,3 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/script/israw.astro.snap b/packages/vscode/test/grammar/fixtures/script/israw.astro.snap
new file mode 100644
index 00000000..7371db28
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/israw.astro.snap
@@ -0,0 +1,13 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/script/json.astro b/packages/vscode/test/grammar/fixtures/script/json.astro
new file mode 100644
index 00000000..e6394f64
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/json.astro
@@ -0,0 +1,14 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/script/json.astro.snap b/packages/vscode/test/grammar/fixtures/script/json.astro.snap
new file mode 100644
index 00000000..74989314
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/json.astro.snap
@@ -0,0 +1,39 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/script/jstypes.astro b/packages/vscode/test/grammar/fixtures/script/jstypes.astro
new file mode 100644
index 00000000..829e2952
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/jstypes.astro
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
diff --git a/packages/vscode/test/grammar/fixtures/script/jstypes.astro.snap b/packages/vscode/test/grammar/fixtures/script/jstypes.astro.snap
new file mode 100644
index 00000000..cea82245
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/jstypes.astro.snap
@@ -0,0 +1,68 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/script/module.astro b/packages/vscode/test/grammar/fixtures/script/module.astro
new file mode 100644
index 00000000..cff07e13
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/module.astro
@@ -0,0 +1,3 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/script/module.astro.snap b/packages/vscode/test/grammar/fixtures/script/module.astro.snap
new file mode 100644
index 00000000..6303c7ff
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/module.astro.snap
@@ -0,0 +1,17 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/script/script.astro b/packages/vscode/test/grammar/fixtures/script/script.astro
new file mode 100644
index 00000000..45ce08a9
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/script.astro
@@ -0,0 +1,3 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/script/script.astro.snap b/packages/vscode/test/grammar/fixtures/script/script.astro.snap
new file mode 100644
index 00000000..f7c3bf56
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/script.astro.snap
@@ -0,0 +1,11 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/script/unknowntype.astro b/packages/vscode/test/grammar/fixtures/script/unknowntype.astro
new file mode 100644
index 00000000..e16f83fb
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/unknowntype.astro
@@ -0,0 +1,3 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/script/unknowntype.astro.snap b/packages/vscode/test/grammar/fixtures/script/unknowntype.astro.snap
new file mode 100644
index 00000000..7825bd31
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/script/unknowntype.astro.snap
@@ -0,0 +1,17 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/style/israw.astro b/packages/vscode/test/grammar/fixtures/style/israw.astro
new file mode 100644
index 00000000..6058d374
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/israw.astro
@@ -0,0 +1,5 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/style/israw.astro.snap b/packages/vscode/test/grammar/fixtures/style/israw.astro.snap
new file mode 100644
index 00000000..de73486d
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/israw.astro.snap
@@ -0,0 +1,17 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/style/less.astro b/packages/vscode/test/grammar/fixtures/style/less.astro
new file mode 100644
index 00000000..c44d01f9
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/less.astro
@@ -0,0 +1,9 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/style/less.astro.snap b/packages/vscode/test/grammar/fixtures/style/less.astro.snap
new file mode 100644
index 00000000..471a1f6e
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/less.astro.snap
@@ -0,0 +1,28 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/style/sass.astro b/packages/vscode/test/grammar/fixtures/style/sass.astro
new file mode 100644
index 00000000..4811ffcd
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/sass.astro
@@ -0,0 +1,8 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/style/sass.astro.snap b/packages/vscode/test/grammar/fixtures/style/sass.astro.snap
new file mode 100644
index 00000000..a9835621
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/sass.astro.snap
@@ -0,0 +1,26 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/style/scss.astro b/packages/vscode/test/grammar/fixtures/style/scss.astro
new file mode 100644
index 00000000..e633b7f1
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/scss.astro
@@ -0,0 +1,9 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/style/scss.astro.snap b/packages/vscode/test/grammar/fixtures/style/scss.astro.snap
new file mode 100644
index 00000000..62daac77
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/scss.astro.snap
@@ -0,0 +1,28 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/style/style.astro b/packages/vscode/test/grammar/fixtures/style/style.astro
new file mode 100644
index 00000000..b7846767
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/style.astro
@@ -0,0 +1,3 @@
+
diff --git a/packages/vscode/test/grammar/fixtures/style/style.astro.snap b/packages/vscode/test/grammar/fixtures/style/style.astro.snap
new file mode 100644
index 00000000..fe679a8d
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/style.astro.snap
@@ -0,0 +1,11 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/fixtures/style/stylus.astro b/packages/vscode/test/grammar/fixtures/style/stylus.astro
new file mode 100644
index 00000000..da2e44b3
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/stylus.astro
@@ -0,0 +1,9 @@
+
+
+
diff --git a/packages/vscode/test/grammar/fixtures/style/stylus.astro.snap b/packages/vscode/test/grammar/fixtures/style/stylus.astro.snap
new file mode 100644
index 00000000..60189c1d
--- /dev/null
+++ b/packages/vscode/test/grammar/fixtures/style/stylus.astro.snap
@@ -0,0 +1,38 @@
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
+>
+#^^ source.astro punctuation.definition.tag.begin.html
+# ^^^^^ source.astro entity.name.tag.html
+# ^ source.astro punctuation.definition.tag.end.html
+>
\ No newline at end of file
diff --git a/packages/vscode/test/grammar/test.mjs b/packages/vscode/test/grammar/test.mjs
new file mode 100644
index 00000000..0fdb432e
--- /dev/null
+++ b/packages/vscode/test/grammar/test.mjs
@@ -0,0 +1,55 @@
+import { spawn } from 'child_process';
+import { readdirSync } from 'fs';
+import { join, resolve, dirname } from 'path';
+import { fileURLToPath } from 'url';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+
+const dummyGrammarDir = resolve(__dirname, './dummy');
+const dummyGrammars = readdirSync(dummyGrammarDir).map(file => join(dummyGrammarDir, file));
+
+const grammarDir = resolve(__dirname, '../../syntaxes');
+const grammars = readdirSync(grammarDir)
+ .filter(file => file.endsWith('.json'))
+ .map(file => join(grammarDir, file));
+
+const allGrammars = [...grammars, ...dummyGrammars];
+
+/**
+ * @param {Parameters} arg
+ */
+function promisifySpawn(...arg) {
+ const childProcess = spawn(...arg);
+ return new Promise(resolve => {
+ childProcess.on('exit', code => {
+ resolve(code);
+ });
+
+ childProcess.on('error', err => {
+ console.error(err);
+ resolve(1);
+ });
+ });
+}
+
+async function snapShotTest() {
+ const extraArgs = process.argv.slice(2);
+ const args = [
+ 'vscode-tmgrammar-snap',
+ '-s',
+ 'source.astro',
+ './test/grammar/fixtures/**/*.astro',
+ ...allGrammars.reduce((/** @type string[] */ previous, path) => [...previous, '-g', path], []),
+ ...extraArgs,
+ ];
+
+ const code = await promisifySpawn(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', args, {
+ stdio: 'inherit',
+ });
+
+ if (code > 0) {
+ process.exit(code);
+ }
+}
+
+snapShotTest();
diff --git a/packages/vscode/test/tsconfig.json b/packages/vscode/test/tsconfig.json
new file mode 100644
index 00000000..17415f80
--- /dev/null
+++ b/packages/vscode/test/tsconfig.json
@@ -0,0 +1,13 @@
+{
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "module": "ES2020",
+ "target": "ES2020",
+ "allowJs": true,
+ "checkJs": true,
+ "rootDir": ".",
+ "emitDeclarationOnly": false,
+ "noEmit": true
+ },
+ "include": ["**/*.js", "grammar/test.mjs"]
+}
diff --git a/packages/vscode/tsconfig.base.json b/packages/vscode/tsconfig.base.json
deleted file mode 100644
index 0f560706..00000000
--- a/packages/vscode/tsconfig.base.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "compilerOptions": {
- "target": "es2019",
- "lib": ["ESNext"],
- "module": "commonjs",
- "moduleResolution": "node",
- "sourceMap": true,
- "composite": true,
- "declaration": true,
- "strict": true,
- "skipLibCheck": true,
- "baseUrl": "./",
- "paths": {
- "@astro-vscode/*": ["packages/*/src"]
- }
- }
-}
diff --git a/yarn.lock b/yarn.lock
index 5c45b7f4..aa04ec9a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1464,7 +1464,7 @@ chainsaw@~0.1.0:
dependencies:
traverse ">=0.3.0 <0.4"
-chalk@^2.0.0, chalk@^2.1.0:
+chalk@^2.0.0, chalk@^2.1.0, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
@@ -1628,6 +1628,11 @@ comma-separated-tokens@^2.0.0:
resolved "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.2.tgz"
integrity sha512-G5yTt3KQN4Yn7Yk4ed73hlZ1evrFKXeUW3086p3PRFNp7m2vIjI6Pg+Kgb+oyzhd9F2qdcoj67+y3SdxL5XWsg==
+commander@^9.2.0:
+ version "9.2.0"
+ resolved "https://registry.yarnpkg.com/commander/-/commander-9.2.0.tgz#6e21014b2ed90d8b7c9647230d8b7a94a4a419a9"
+ integrity sha512-e2i4wANQiSXgnrBlIatyHtP1odfUp0BbV5Y5nEGbxtIrStkEOAAzCUirvLBNXHLr7kwLvJl6V+4V3XV9x7Wd9w==
+
common-ancestor-path@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz"
@@ -1809,7 +1814,7 @@ diff@5.0.0, diff@^5.0.0:
resolved "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz"
integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==
-diff@^4.0.1:
+diff@^4.0.1, diff@^4.0.2:
version "4.0.2"
resolved "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
@@ -2663,6 +2668,18 @@ glob@7.2.0, glob@^7.1.3, glob@^7.2.0:
once "^1.3.0"
path-is-absolute "^1.0.0"
+glob@^7.1.6:
+ version "7.2.3"
+ resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
+ integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==
+ dependencies:
+ fs.realpath "^1.0.0"
+ inflight "^1.0.4"
+ inherits "2"
+ minimatch "^3.1.1"
+ once "^1.3.0"
+ path-is-absolute "^1.0.0"
+
globals@^11.1.0:
version "11.12.0"
resolved "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz"
@@ -4066,7 +4083,7 @@ minimatch@4.2.1:
dependencies:
brace-expansion "^1.1.7"
-minimatch@^3.0.4:
+minimatch@^3.0.4, minimatch@^3.1.1:
version "3.1.2"
resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz"
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
@@ -5939,7 +5956,7 @@ vscode-nls@^5.0.1:
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.0.1.tgz#ba23fc4d4420d25e7f886c8e83cbdcec47aa48b2"
integrity sha512-hHQV6iig+M21lTdItKPkJAaWrxALQb/nqpVffakO4knJOh3DrU2SXOMzUzNgo1eADPzu3qSsJY1weCzvR52q9A==
-vscode-oniguruma@^1.6.1:
+vscode-oniguruma@^1.5.1, vscode-oniguruma@^1.6.1:
version "1.6.2"
resolved "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.6.2.tgz"
integrity sha512-KH8+KKov5eS/9WhofZR8M8dMHWN2gTxjMsG4jd04YhpbPR91fUj7rYQ2/XjeHCJWbg7X++ApRIU9NUwM2vTvLA==
@@ -5949,6 +5966,23 @@ vscode-textmate@5.2.0:
resolved "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-5.2.0.tgz"
integrity sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==
+vscode-textmate@^7.0.1:
+ version "7.0.1"
+ resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-7.0.1.tgz#8118a32b02735dccd14f893b495fa5389ad7de79"
+ integrity sha512-zQ5U/nuXAAMsh691FtV0wPz89nSkHbs+IQV8FDk+wew9BlSDhf4UmWGlWJfTR2Ti6xZv87Tj5fENzKf6Qk7aLw==
+
+vscode-tmgrammar-test@^0.1.1:
+ version "0.1.1"
+ resolved "https://registry.yarnpkg.com/vscode-tmgrammar-test/-/vscode-tmgrammar-test-0.1.1.tgz#a3b30956c5fc7ec336fa92a1943587a7452f5e95"
+ integrity sha512-0WvD3U+E0KV95bNT7v5g7PQ85JfAjh9MuXOy1dgwZskkCsA8ASiSy60iv30JOZrM6dBjJZooGUAybRAIB+Song==
+ dependencies:
+ chalk "^2.4.2"
+ commander "^9.2.0"
+ diff "^4.0.2"
+ glob "^7.1.6"
+ vscode-oniguruma "^1.5.1"
+ vscode-textmate "^7.0.1"
+
vscode-uri@^2.1.2:
version "2.1.2"
resolved "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz"