From b7c16293ee69d2cea437591b988d51f291cec15f Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Mon, 16 May 2022 11:49:14 -0400 Subject: [PATCH 01/13] Fix expressions block not having TSX-like highlight on the brackets --- .../languages/astro-language-configuration.json | 1 - packages/vscode/syntaxes/astro.tmLanguage.json | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vscode/languages/astro-language-configuration.json b/packages/vscode/languages/astro-language-configuration.json index 5e761af0..51abc9cd 100644 --- a/packages/vscode/languages/astro-language-configuration.json +++ b/packages/vscode/languages/astro-language-configuration.json @@ -3,7 +3,6 @@ "blockComment": [""] }, "brackets": [ - ["---", "---"], [""], ["<", ">"], ["{", "}"], diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index e19e4346..9b0fd592 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -445,16 +445,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 +500,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 +516,7 @@ "end": "(^|\\G)(-{3})|\\.{3}\\s*$", "endCaptures": { "2": { - "name": "comment.block.html" + "name": "comment" } } }, From 6dcdef4500e60de3f0b0cf5f1d157a205d306197 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Mon, 16 May 2022 13:41:15 -0400 Subject: [PATCH 02/13] Add template literal to surroundingPairs --- packages/vscode/languages/astro-language-configuration.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vscode/languages/astro-language-configuration.json b/packages/vscode/languages/astro-language-configuration.json index 51abc9cd..1098af49 100644 --- a/packages/vscode/languages/astro-language-configuration.json +++ b/packages/vscode/languages/astro-language-configuration.json @@ -22,6 +22,7 @@ "surroundingPairs": [ { "open": "'", "close": "'" }, { "open": "\"", "close": "\"" }, + { "open": "`", "close": "`" }, { "open": "{", "close": "}" }, { "open": "[", "close": "]" }, { "open": "(", "close": ")" }, From fc51b20031b418ce238b038dc28f40849ec5a365 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Mon, 16 May 2022 19:09:24 -0400 Subject: [PATCH 03/13] Add grammar test suite --- packages/vscode/package.json | 8 ++- .../grammar/dummy/css.tmLanguage-dummy.json | 4 ++ .../grammar/dummy/html.tmLanguage-dummy.json | 4 ++ .../grammar/dummy/js.tmLanguage-dummy.json | 4 ++ .../grammar/dummy/less.tsLanguage-dummy.json | 4 ++ .../dummy/markdown.tmLanguage-dummy.json | 4 ++ .../grammar/dummy/sass.tmLanguage-dummy.json | 4 ++ .../grammar/dummy/scss.tsLanguage-dummy.json | 4 ++ .../dummy/stylus.tmLanguage-dummy.json | 4 ++ .../grammar/dummy/ts.tmLanguage-dummy.json | 4 ++ .../grammar/dummy/tsx.tmLanguage-dummy.json | 4 ++ .../grammar/fixtures/markdown/markdown.astro | 7 +++ .../fixtures/markdown/markdown.astro.snap | 18 ++++++ .../test/grammar/fixtures/style/style.astro | 3 + .../grammar/fixtures/style/style.astro.snap | 11 ++++ packages/vscode/test/grammar/test.mjs | 55 +++++++++++++++++++ packages/vscode/test/tsconfig.json | 13 +++++ packages/vscode/tsconfig.base.json | 17 ------ yarn.lock | 42 ++++++++++++-- 19 files changed, 191 insertions(+), 23 deletions(-) create mode 100644 packages/vscode/test/grammar/dummy/css.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/html.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/js.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/less.tsLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/markdown.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/sass.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/scss.tsLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/stylus.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/ts.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/tsx.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/fixtures/markdown/markdown.astro create mode 100644 packages/vscode/test/grammar/fixtures/markdown/markdown.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/style/style.astro create mode 100644 packages/vscode/test/grammar/fixtures/style/style.astro.snap create mode 100644 packages/vscode/test/grammar/test.mjs create mode 100644 packages/vscode/test/tsconfig.json delete mode 100644 packages/vscode/tsconfig.base.json diff --git a/packages/vscode/package.json b/packages/vscode/package.json index a30d58cd..75895acf 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", 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/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/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/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/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" From cbe581bc1db52c7925cf30c99ae797f73c32e56d Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Mon, 16 May 2022 21:15:37 -0400 Subject: [PATCH 04/13] Add README to test directory, add tests for style tags --- packages/vscode/test/grammar/README.md | 5 +++ .../test/grammar/fixtures/style/less.astro | 9 +++++ .../grammar/fixtures/style/less.astro.snap | 28 ++++++++++++++ .../test/grammar/fixtures/style/sass.astro | 8 ++++ .../grammar/fixtures/style/sass.astro.snap | 26 +++++++++++++ .../test/grammar/fixtures/style/scss.astro | 9 +++++ .../grammar/fixtures/style/scss.astro.snap | 28 ++++++++++++++ .../test/grammar/fixtures/style/stylus.astro | 9 +++++ .../grammar/fixtures/style/stylus.astro.snap | 38 +++++++++++++++++++ 9 files changed, 160 insertions(+) create mode 100644 packages/vscode/test/grammar/README.md create mode 100644 packages/vscode/test/grammar/fixtures/style/less.astro create mode 100644 packages/vscode/test/grammar/fixtures/style/less.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/style/sass.astro create mode 100644 packages/vscode/test/grammar/fixtures/style/sass.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/style/scss.astro create mode 100644 packages/vscode/test/grammar/fixtures/style/scss.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/style/stylus.astro create mode 100644 packages/vscode/test/grammar/fixtures/style/stylus.astro.snap 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/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/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 From 36414238b38e4a8dfb4de0330d25e929fff9ece3 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 17 May 2022 13:52:38 -0400 Subject: [PATCH 05/13] Add support for `is:raw`, maybe? --- .../vscode/syntaxes/astro.tmLanguage.json | 35 ++++++++++++ .../test/grammar/fixtures/raw/israw.astro | 11 ++++ .../grammar/fixtures/raw/israw.astro.snap | 55 +++++++++++++++++++ .../test/grammar/fixtures/script/script.astro | 3 + .../grammar/fixtures/script/script.astro.snap | 11 ++++ 5 files changed, 115 insertions(+) create mode 100644 packages/vscode/test/grammar/fixtures/raw/israw.astro create mode 100644 packages/vscode/test/grammar/fixtures/raw/israw.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/script/script.astro create mode 100644 packages/vscode/test/grammar/fixtures/script/script.astro.snap diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index 9b0fd592..c5837096 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -367,6 +367,41 @@ }, "html:element": { "patterns": [ + { + "name": "astro.element.raw", + "begin": "(<)([^/?!\\s<>]+)(.+is:raw.*?)(>)", + "end": "(]+)(?=\\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.plaintext" + }, { "name": "meta.tag.any.$2.start.html", "begin": "(<)([^/?!\\s<>]+)(?=\\s|/?>)", 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..75f0f580 --- /dev/null +++ b/packages/vscode/test/grammar/fixtures/raw/israw.astro @@ -0,0 +1,11 @@ +
+ 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..3b340cbf --- /dev/null +++ b/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap @@ -0,0 +1,55 @@ +>
+#^ 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.plaintext +>
+#^^ 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.plaintext +>
+#^^ 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.plaintext +>
+#^^ 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 +> \ 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 From f2198d0dd2104575d505203ea025931a4a9c54a0 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 17 May 2022 19:26:40 -0400 Subject: [PATCH 06/13] Add is:raw for script and style tags, add support for script tags with different types --- packages/vscode/package.json | 1 + .../vscode/syntaxes/astro.tmLanguage.json | 69 +++++++++++++++++++ .../test/grammar/fixtures/script/israw.astro | 3 + .../grammar/fixtures/script/israw.astro.snap | 13 ++++ .../test/grammar/fixtures/script/json.astro | 14 ++++ .../grammar/fixtures/script/json.astro.snap | 39 +++++++++++ .../test/grammar/fixtures/script/module.astro | 3 + .../grammar/fixtures/script/module.astro.snap | 17 +++++ .../grammar/fixtures/script/unknowntype.astro | 3 + .../fixtures/script/unknowntype.astro.snap | 17 +++++ .../test/grammar/fixtures/style/israw.astro | 5 ++ .../grammar/fixtures/style/israw.astro.snap | 17 +++++ 12 files changed, 201 insertions(+) create mode 100644 packages/vscode/test/grammar/fixtures/script/israw.astro create mode 100644 packages/vscode/test/grammar/fixtures/script/israw.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/script/json.astro create mode 100644 packages/vscode/test/grammar/fixtures/script/json.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/script/module.astro create mode 100644 packages/vscode/test/grammar/fixtures/script/module.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/script/unknowntype.astro create mode 100644 packages/vscode/test/grammar/fixtures/script/unknowntype.astro.snap create mode 100644 packages/vscode/test/grammar/fixtures/style/israw.astro create mode 100644 packages/vscode/test/grammar/fixtures/style/israw.astro.snap diff --git a/packages/vscode/package.json b/packages/vscode/package.json index 75895acf..f8dedf36 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -256,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 c5837096..35e8e2be 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -131,6 +131,48 @@ } }, "patterns": [ + { + "comment": "Treat script tag with application/ld+json as JSON, why not", + "begin": "\\G(?=\\s*[^>]*?type\\s*=\\s*(['\"]|)(?i:application/ld\\+json)\\1)", + "end": "(?=)", + "patterns": [ + { + "begin": "(?<=>)(?!]*?is:raw)", + "end": "(?=)", + "patterns": [ + { + "begin": "(?<=>)(?!]*?type\\s*=\\s*(['\"]|)(?i:module|text/javascript)\\1)", + "end": "(?=)", + "patterns": [ + { + "begin": "(?<=>)(?!]*?lang\\s*=\\s*(['\"]|)(?i:jsx?|javascript)\\1)", "end": "(?=)", @@ -170,6 +212,19 @@ { "include": "#html:tag-attributes" } ] }, + { + "comment": "Treat anything with an unknown type as unknown (plaintext)", + "begin": "\\G(?=\\s*[^>]*?type\\s*=\\s*(['\"]|)\\1)", + "end": "(?=)", + "patterns": [ + { + "begin": "(?<=>)(?!)(?!]*?is:raw)", + "end": "(?=)", + "patterns": [ + { + "begin": "(?<=>)(?!]*?lang\\s*=\\s*(['\"]|)(?i:css)\\1)", "end": "(?=)", 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..412d5919 --- /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..0b7b5921 --- /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/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/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..a6072481 --- /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 From d94764be52bfbcc963683c934915bc849ec08e32 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 17 May 2022 19:31:25 -0400 Subject: [PATCH 07/13] Fix missing dummies, use source.unknown for `is:raw` --- .../vscode/syntaxes/astro.tmLanguage.json | 12 +++++----- .../grammar/dummy/json.tmLanguage-dummy.json | 4 ++++ .../dummy/unknown.tmLanguage-dummy.json | 4 ++++ .../grammar/fixtures/raw/israw.astro.snap | 6 ++--- .../grammar/fixtures/script/israw.astro.snap | 2 +- .../grammar/fixtures/script/json.astro.snap | 24 +++++++++---------- .../grammar/fixtures/style/israw.astro.snap | 6 ++--- 7 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 packages/vscode/test/grammar/dummy/json.tmLanguage-dummy.json create mode 100644 packages/vscode/test/grammar/dummy/unknown.tmLanguage-dummy.json diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index 35e8e2be..5f3c9e2c 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -153,8 +153,8 @@ { "begin": "(?<=>)(?!]*?type\\s*=\\s*(['\"]|)\\1)", "end": "(?=)", "patterns": [ @@ -268,8 +268,8 @@ { "begin": "(?<=>)(?! Hello -#^^^^^^^ source.astro astro.element.raw source.plaintext +#^^^^^^^ 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 @@ -26,7 +26,7 @@ # ^^^^^^ 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.plaintext +#^^^^^^^ 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 @@ -47,7 +47,7 @@ # ^^^^^^^^^ 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.plaintext +#^^^^^^^ 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 diff --git a/packages/vscode/test/grammar/fixtures/script/israw.astro.snap b/packages/vscode/test/grammar/fixtures/script/israw.astro.snap index 412d5919..3e038dff 100644 --- a/packages/vscode/test/grammar/fixtures/script/israw.astro.snap +++ b/packages/vscode/test/grammar/fixtures/script/israw.astro.snap @@ -5,7 +5,7 @@ # ^^^^^^ source.astro meta.attribute.is:raw.html entity.other.attribute-name.html # ^ source.astro punctuation.definition.tag.end.html > "hello" -#^^^^^^^^^ source.astro +#^^^^^^^^^ source.astro source.unknown > #^^ source.astro punctuation.definition.tag.begin.html # ^^^^^^ source.astro entity.name.tag.html diff --git a/packages/vscode/test/grammar/fixtures/script/json.astro.snap b/packages/vscode/test/grammar/fixtures/script/json.astro.snap index 0b7b5921..74989314 100644 --- a/packages/vscode/test/grammar/fixtures/script/json.astro.snap +++ b/packages/vscode/test/grammar/fixtures/script/json.astro.snap @@ -9,29 +9,29 @@ # ^ source.astro string.quoted.double.html punctuation.definition.string.end.html # ^ source.astro punctuation.definition.tag.end.html > { -#^^^^ source.astro +#^^^^ source.astro source.json > "@context": "https://schema.org/", -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > "@type": "Recipe", -#^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > "name": "Party Coffee Cake", -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > "author": { -#^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^ source.astro source.json > "@type": "Person", -#^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > "name": "Mary Stone" -#^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > }, -#^^^^^^^ source.astro +#^^^^^^^ source.astro source.json > "datePublished": "2018-03-10", -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > "description": "This coffee cake is awesome and perfect for parties.", -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > "prepTime": "PT20M" -#^^^^^^^^^^^^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.json > } -#^^^^ source.astro +#^^^^ source.astro source.json > #^^ source.astro punctuation.definition.tag.begin.html # ^^^^^^ source.astro entity.name.tag.html diff --git a/packages/vscode/test/grammar/fixtures/style/israw.astro.snap b/packages/vscode/test/grammar/fixtures/style/israw.astro.snap index a6072481..545e2b29 100644 --- a/packages/vscode/test/grammar/fixtures/style/israw.astro.snap +++ b/packages/vscode/test/grammar/fixtures/style/israw.astro.snap @@ -5,11 +5,11 @@ # ^^^^^^ source.astro meta.attribute.is:raw.html entity.other.attribute-name.html # ^ source.astro punctuation.definition.tag.end.html > h1 { -#^^^^^^ source.astro +#^^^^^^ source.astro source.unknown > color: red -#^^^^^^^^^^^^^ source.astro +#^^^^^^^^^^^^^ source.astro source.unknown > } -#^^^ source.astro +#^^^ source.astro source.unknown > #^^ source.astro punctuation.definition.tag.begin.html # ^^^^^ source.astro entity.name.tag.html From 0e770ddaee40582968ed5a7233b54531628e4b9d Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Thu, 19 May 2022 20:24:51 -0400 Subject: [PATCH 08/13] Add auto indent support, add wordPattern regex --- .../astro-language-configuration.json | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/vscode/languages/astro-language-configuration.json b/packages/vscode/languages/astro-language-configuration.json index 1098af49..83eeee44 100644 --- a/packages/vscode/languages/astro-language-configuration.json +++ b/packages/vscode/languages/astro-language-configuration.json @@ -5,8 +5,7 @@ "brackets": [ [""], ["<", ">"], - ["{", "}"], - ["(", ")"] + ["{", "}"] ], "autoClosingPairs": [ { "open": "{", "close": "}" }, @@ -15,8 +14,9 @@ { "open": "'", "close": "'" }, { "open": "\"", "close": "\"" }, { "open": "`", "close": "`" }, + { "open": "{/*", "close": "*/}", "notIn": ["comment", "string"] }, { "open": "", "notIn": ["comment", "string"] }, - { "open": "/**", "close": " */", "notIn": ["string"] } + { "open": "/**", "close": " */", "notIn": ["string", "comment"] } ], "autoCloseBefore": ";:.,=}])>` \n\t", "surroundingPairs": [ @@ -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[^>]*>|-->|\\})" } } From f08c27625eba0f3e6d184fb33cc248e95a5017d1 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Thu, 19 May 2022 20:25:29 -0400 Subject: [PATCH 09/13] Add support for more JS-like types, inspired by compiler's TSX --- .../vscode/syntaxes/astro.tmLanguage.json | 30 ++++---- .../grammar/fixtures/script/jstypes.astro | 15 ++++ .../fixtures/script/jstypes.astro.snap | 68 +++++++++++++++++++ 3 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 packages/vscode/test/grammar/fixtures/script/jstypes.astro create mode 100644 packages/vscode/test/grammar/fixtures/script/jstypes.astro.snap diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index 5f3c9e2c..a75ca00d 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -132,7 +132,7 @@ }, "patterns": [ { - "comment": "Treat script tag with application/ld+json as JSON, why not", + "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": [ @@ -160,8 +160,8 @@ ] }, { - "comment": "Treat script tag with type=module or type=text/javascript as JS", - "begin": "\\G(?=\\s*[^>]*?type\\s*=\\s*(['\"]|)(?i:module|text/javascript)\\1)", + "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": [ { @@ -174,53 +174,53 @@ ] }, { - "begin": "\\G(?=\\s*[^>]*?lang\\s*=\\s*(['\"]|)(?i:jsx?|javascript)\\1)", + "comment": "Treat anything with an unknown type as unknown", + "begin": "\\G(?=\\s*[^>]*?type\\s*=\\s*(['\"]|)\\1)", "end": "(?=)", "patterns": [ { "begin": "(?<=>)(?!]*?lang\\s*=\\s*(['\"]|)(?i:ts|typescript)\\1)", + "begin": "\\G(?=\\s*[^>]*?lang\\s*=\\s*(['\"]|)(?i:jsx?|javascript)\\1)", "end": "(?=)", "patterns": [ { "begin": "(?<=>)(?!]*?lang\\s*=\\s*(['\"]|)(?i:tsx)\\1)", + "begin": "\\G(?=\\s*[^>]*?lang\\s*=\\s*(['\"]|)(?i:ts|typescript)\\1)", "end": "(?=)", "patterns": [ { "begin": "(?<=>)(?!]*?type\\s*=\\s*(['\"]|)\\1)", + "begin": "\\G(?=\\s*[^>]*?lang\\s*=\\s*(['\"]|)(?i:tsx)\\1)", "end": "(?=)", "patterns": [ { "begin": "(?<=>)(?! + console.log("") + + + + + + + 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 From ebe92b7ace3a196f98949c6992a25f40e9be1ee7 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Thu, 19 May 2022 20:37:30 -0400 Subject: [PATCH 10/13] Add spaces in comment completions --- packages/vscode/languages/astro-language-configuration.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vscode/languages/astro-language-configuration.json b/packages/vscode/languages/astro-language-configuration.json index 83eeee44..99ad2474 100644 --- a/packages/vscode/languages/astro-language-configuration.json +++ b/packages/vscode/languages/astro-language-configuration.json @@ -14,9 +14,9 @@ { "open": "'", "close": "'" }, { "open": "\"", "close": "\"" }, { "open": "`", "close": "`" }, - { "open": "{/*", "close": "*/}", "notIn": ["comment", "string"] }, - { "open": "", "notIn": ["comment", "string"] }, - { "open": "/**", "close": " */", "notIn": ["string", "comment"] } + { "open": "{/*", "close": " */}", "notIn": ["comment", "string"] }, + { "open": "", "notIn": ["comment", "string"] }, + { "open": "/**", "close": " */", "notIn": ["string"] } ], "autoCloseBefore": ";:.,=}])>` \n\t", "surroundingPairs": [ From 8fe025a7ee98c9c6fe051ac462dacd8026fbf3be Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Fri, 20 May 2022 10:47:41 -0400 Subject: [PATCH 11/13] Add support for is:raw components --- .../vscode/syntaxes/astro.tmLanguage.json | 73 ++++++++++++++----- .../fixtures/components/component.astro | 3 + .../fixtures/components/component.astro.snap | 17 +++++ .../test/grammar/fixtures/raw/israw.astro | 4 + .../grammar/fixtures/raw/israw.astro.snap | 13 ++++ 5 files changed, 93 insertions(+), 17 deletions(-) create mode 100644 packages/vscode/test/grammar/fixtures/components/component.astro create mode 100644 packages/vscode/test/grammar/fixtures/components/component.astro.snap diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index a75ca00d..8bbf74b6 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": "(]*|[^/?!\\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": "(]*|[^/?!\\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": "(]*|[^/?!\\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" + } + ] } ] }, 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/raw/israw.astro b/packages/vscode/test/grammar/fixtures/raw/israw.astro index 75f0f580..d0b910e3 100644 --- a/packages/vscode/test/grammar/fixtures/raw/israw.astro +++ b/packages/vscode/test/grammar/fixtures/raw/israw.astro @@ -9,3 +9,7 @@
Hello
+ + + Hello + diff --git a/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap b/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap index 93c5a3b1..43f870fc 100644 --- a/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap +++ b/packages/vscode/test/grammar/fixtures/raw/israw.astro.snap @@ -52,4 +52,17 @@ #^^ 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 From 04d3d625284c526d690018df41a8552a1dfb7154 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Fri, 20 May 2022 10:50:05 -0400 Subject: [PATCH 12/13] Add changeset --- .changeset/selfish-icons-breathe.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/selfish-icons-breathe.md 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 From 1154e1e961a85cc1178b74f760d89dce366e4287 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Fri, 20 May 2022 17:02:56 -0400 Subject: [PATCH 13/13] Remove is:raw on script tags and style tags since it doesn't do anything there --- .../vscode/syntaxes/astro.tmLanguage.json | 28 ------------------- .../grammar/fixtures/script/israw.astro.snap | 2 +- .../grammar/fixtures/style/israw.astro.snap | 6 ++-- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index 8bbf74b6..c93486dd 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -184,20 +184,6 @@ { "include": "#html:tag-attributes" } ] }, - { - "comment": "Treat script tag with is:raw as plain text", - "begin": "\\G(?=\\s*[^>]*?is:raw)", - "end": "(?=)", - "patterns": [ - { - "begin": "(?<=>)(?!]*?type\\s*=\\s*(['\"]|)(?i:module|(?:text/javascript|text/partytown|application/node|application/javascript))\\1)", @@ -299,20 +285,6 @@ } }, "patterns": [ - { - "comment": "Treat style tag with is:raw as plain text", - "begin": "\\G(?=\\s*[^>]*?is:raw)", - "end": "(?=)", - "patterns": [ - { - "begin": "(?<=>)(?!]*?lang\\s*=\\s*(['\"]|)(?i:css)\\1)", "end": "(?=)", diff --git a/packages/vscode/test/grammar/fixtures/script/israw.astro.snap b/packages/vscode/test/grammar/fixtures/script/israw.astro.snap index 3e038dff..7371db28 100644 --- a/packages/vscode/test/grammar/fixtures/script/israw.astro.snap +++ b/packages/vscode/test/grammar/fixtures/script/israw.astro.snap @@ -5,7 +5,7 @@ # ^^^^^^ source.astro meta.attribute.is:raw.html entity.other.attribute-name.html # ^ source.astro punctuation.definition.tag.end.html > "hello" -#^^^^^^^^^ source.astro source.unknown +#^^^^^^^^^ source.astro source.js > #^^ source.astro punctuation.definition.tag.begin.html # ^^^^^^ source.astro entity.name.tag.html diff --git a/packages/vscode/test/grammar/fixtures/style/israw.astro.snap b/packages/vscode/test/grammar/fixtures/style/israw.astro.snap index 545e2b29..de73486d 100644 --- a/packages/vscode/test/grammar/fixtures/style/israw.astro.snap +++ b/packages/vscode/test/grammar/fixtures/style/israw.astro.snap @@ -5,11 +5,11 @@ # ^^^^^^ source.astro meta.attribute.is:raw.html entity.other.attribute-name.html # ^ source.astro punctuation.definition.tag.end.html > h1 { -#^^^^^^ source.astro source.unknown +#^^^^^^ source.astro source.css > color: red -#^^^^^^^^^^^^^ source.astro source.unknown +#^^^^^^^^^^^^^ source.astro source.css > } -#^^^ source.astro source.unknown +#^^^ source.astro source.css > #^^ source.astro punctuation.definition.tag.begin.html # ^^^^^ source.astro entity.name.tag.html