From 56dae96c95b7158094991a37ebfdf01076cc58f8 Mon Sep 17 00:00:00 2001 From: Goulven Clec'h Date: Wed, 13 Mar 2024 19:54:44 +0100 Subject: [PATCH] =?UTF-8?q?Let's=20take=20down=20Microsoft!=20=F0=9F=A6=9C?= =?UTF-8?q?=F0=9F=8F=B4=E2=80=8D=E2=98=A0=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/package.json | 12 ++++-- .../vscode/syntaxes/astro.tmLanguage.json | 4 +- .../vscode/syntaxes/astro.tmLanguage.src.yaml | 4 +- .../vscode/syntaxes/astroJSX.tmLanguage.json | 37 +++++++++++++++++++ .../syntaxes/astroJSX.tmLanguage.src.yaml | 36 ++++++++++++++++++ .../syntaxes/markdown.astro.tmLanguage.json | 2 +- 6 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 packages/vscode/syntaxes/astroJSX.tmLanguage.json create mode 100644 packages/vscode/syntaxes/astroJSX.tmLanguage.src.yaml diff --git a/packages/vscode/package.json b/packages/vscode/package.json index b5d5cc16..45a6e325 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -162,8 +162,7 @@ "source.stylus": "stylus", "source.js": "javascript", "source.ts": "typescript", - "source.json": "json", - "source.tsx": "typescriptreact" + "source.json": "json" }, "unbalancedBracketScopes": [ "keyword.operator.relational", @@ -176,11 +175,16 @@ { "scopeName": "text.html.markdown.astro", "path": "./syntaxes/markdown.astro.tmLanguage.json", - "injectTo": ["text.html.markdown", "source.astro"], + "injectTo": ["text.html.markdown"], "embeddedLanguages": { "meta.embedded.block.astro": "astro", "meta.embedded.block.astro.frontmatter": "typescriptreact" } + }, + { + "scopeName": "source.astroJSX", + "path": "./syntaxes/astroJSX.tmLanguage.json", + "injectTo": ["source.astro"] } ] }, @@ -188,7 +192,7 @@ "prebuild": "cd ../ts-plugin && pnpm build", "build": "pnpm prebuild && node scripts/build.mjs -- --minify", "dev": "node scripts/build.mjs -- --watch", - "build:grammar": "npx js-yaml syntaxes/astro.tmLanguage.src.yaml > syntaxes/astro.tmLanguage.json", + "build:grammar": "npx js-yaml syntaxes/astro.tmLanguage.src.yaml > syntaxes/astro.tmLanguage.json && npx js-yaml syntaxes/astroJSX.tmLanguage.src.yaml > syntaxes/astroJSX.tmLanguage.json", "test": "pnpm test:vscode && pnpm test:grammar", "test:vscode": "node ./test/runTest.js", "test:grammar": "pnpm build:grammar && node ./test/grammar/test.mjs", diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index 515df2b1..a0d1a24d 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -255,7 +255,7 @@ "name": "punctuation.section.embedded.end.astro" } }, - "contentName": "meta.embedded.expression.astro source.tsx", + "contentName": "meta.embedded.expression.astro source.astroJSX", "patterns": [ { "begin": "\\G\\s*(?={)", @@ -267,7 +267,7 @@ ] }, { - "include": "source.tsx" + "include": "source.astroJSX" } ] } diff --git a/packages/vscode/syntaxes/astro.tmLanguage.src.yaml b/packages/vscode/syntaxes/astro.tmLanguage.src.yaml index b7801073..9f876cb8 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.src.yaml +++ b/packages/vscode/syntaxes/astro.tmLanguage.src.yaml @@ -228,13 +228,13 @@ repository: end: \} beginCaptures: { 0: { name: punctuation.section.embedded.begin.astro } } endCaptures: { 0: { name: punctuation.section.embedded.end.astro } } - contentName: meta.embedded.expression.astro source.tsx + contentName: meta.embedded.expression.astro source.astroJSX patterns: # Object literals - usually used within attributes. - begin: \G\s*(?={) end: (?<=}) patterns: [include: source.tsx#object-literal] - - include: source.tsx + - include: source.astroJSX # Entities # Adapted from https://github.com/microsoft/vscode/blob/12605e53052114df3ac512c59936e69c331f0337/extensions/html/syntaxes/html.tmLanguage.json#L532 diff --git a/packages/vscode/syntaxes/astroJSX.tmLanguage.json b/packages/vscode/syntaxes/astroJSX.tmLanguage.json new file mode 100644 index 00000000..2049ef85 --- /dev/null +++ b/packages/vscode/syntaxes/astroJSX.tmLanguage.json @@ -0,0 +1,37 @@ +{ + "name": "AstroJSX", + "scopeName": "source.astroJSX", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#jsx" + } + ], + "repository": { + "comments": { + "begin": "", + "captures": { + "0": { + "name": "punctuation.definition.comment.astroJSX" + } + }, + "name": "comment.block.astroJSX", + "patterns": [ + { + "match": "\\G-?>|)|--!>", + "name": "invalid.illegal.characters-not-allowed-here.astroJSX" + } + ] + }, + "jsx": { + "patterns": [ + { + "include": "source.js.jsx" + } + ] + } + } +} diff --git a/packages/vscode/syntaxes/astroJSX.tmLanguage.src.yaml b/packages/vscode/syntaxes/astroJSX.tmLanguage.src.yaml new file mode 100644 index 00000000..af1558c7 --- /dev/null +++ b/packages/vscode/syntaxes/astroJSX.tmLanguage.src.yaml @@ -0,0 +1,36 @@ +--- +# Let's take down Microsoft! 🦜🏴‍☠️ +# Astro expression syntax is really similar to JSX, but it's not JSX. +# So, we need to create a new syntax for it, where we include the JSX syntax as a base, +# and add some Astro specific patterns over it. +name: AstroJSX +scopeName: source.astroJSX + +patterns: + - include: '#comments' + - include: '#jsx' + +repository: + # ---------- + # HTML PATTERNS + + # Basic HTML comments - not supported by JSX in expressions, but Astro does. + comments: + begin: + captures: + 0: { name: punctuation.definition.comment.astroJSX } + name: comment.block.astroJSX + patterns: + # Validations + - { + match: '\G-?>|)|--!>', + name: invalid.illegal.characters-not-allowed-here.astroJSX, + } + + # ---------- + # JSX PATTERNS + # The foundation for AstroJSX. + jsx: + patterns: + - include: 'source.js.jsx' diff --git a/packages/vscode/syntaxes/markdown.astro.tmLanguage.json b/packages/vscode/syntaxes/markdown.astro.tmLanguage.json index 7f4bf402..c3772151 100644 --- a/packages/vscode/syntaxes/markdown.astro.tmLanguage.json +++ b/packages/vscode/syntaxes/markdown.astro.tmLanguage.json @@ -49,7 +49,7 @@ "contentName": "meta.embedded.block.astro.frontmatter", "patterns": [ { - "include": "source.tsx" + "include": "source.ts" } ] },