From cc0c86b73642c44f6df0fa5b1f5251bd224d5124 Mon Sep 17 00:00:00 2001 From: Goulven CLEC'H Date: Thu, 14 Mar 2024 12:45:35 +0100 Subject: [PATCH] refactor(tmLanguage): text pattern (#830) --- .changeset/two-worms-cover.md | 5 ++ .../vscode/syntaxes/astro.tmLanguage.json | 31 ++++--- .../vscode/syntaxes/astro.tmLanguage.src.yaml | 22 +++-- .../vscode/test/grammar/fixtures/text.astro | 19 ++++- .../test/grammar/fixtures/text.astro.snap | 84 +++++++++++++------ 5 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 .changeset/two-worms-cover.md diff --git a/.changeset/two-worms-cover.md b/.changeset/two-worms-cover.md new file mode 100644 index 00000000..41356728 --- /dev/null +++ b/.changeset/two-worms-cover.md @@ -0,0 +1,5 @@ +--- +"astro-vscode": patch +--- + +text pattern is now after scope & frontmatter patterns diff --git a/packages/vscode/syntaxes/astro.tmLanguage.json b/packages/vscode/syntaxes/astro.tmLanguage.json index 515df2b1..809a3972 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.json +++ b/packages/vscode/syntaxes/astro.tmLanguage.json @@ -1,7 +1,9 @@ { "name": "Astro", "scopeName": "source.astro", - "fileTypes": ["astro"], + "fileTypes": [ + "astro" + ], "injections": { "L:(meta.script.astro) (meta.lang.json) - (meta source)": { "patterns": [ @@ -175,6 +177,9 @@ }, { "include": "#frontmatter" + }, + { + "include": "#text" } ], "repository": { @@ -211,16 +216,6 @@ }, { "include": "#entities" - }, - { - "begin": "(?<=^|>|})", - "end": "(?=<|{|$)", - "name": "text.astro", - "patterns": [ - { - "include": "#entities" - } - ] } ] }, @@ -823,6 +818,20 @@ } }, "name": "meta.scope.tag.$2.astro" + }, + "text": { + "patterns": [ + { + "begin": "(?<=^|---|>|})", + "end": "(?=<|{|$)", + "name": "text.astro", + "patterns": [ + { + "include": "#entities" + } + ] + } + ] } } } diff --git a/packages/vscode/syntaxes/astro.tmLanguage.src.yaml b/packages/vscode/syntaxes/astro.tmLanguage.src.yaml index b7801073..07907782 100644 --- a/packages/vscode/syntaxes/astro.tmLanguage.src.yaml +++ b/packages/vscode/syntaxes/astro.tmLanguage.src.yaml @@ -165,6 +165,7 @@ injections: patterns: - include: '#scope' - include: '#frontmatter' + - include: '#text' # Contains all of our patterns. repository: @@ -193,13 +194,6 @@ repository: - include: '#tags' - include: '#interpolation' - include: '#entities' - # Content text. - # This matches nothing inside of tags, only in-between them and at the beginning/end of the file. - - begin: (?<=^|>|}) - end: (?=<|{|$) - name: text.astro - patterns: - - include: '#entities' # ---------- # COMMENTS @@ -516,3 +510,17 @@ repository: endCaptures: 1: { name: meta.tag.end.astro punctuation.definition.tag.end.astro } name: meta.scope.tag.$2.astro + + # ------ + # TEXT + # This will match any text outside frontmatter and scopes patterns. + + text: + patterns: + # Content text. + # This matches nothing inside of tags, only in-between them and at the beginning/end of the file. + - begin: (?<=^|---|>|}) + end: (?=<|{|$) + name: text.astro + patterns: + - include: '#entities' diff --git a/packages/vscode/test/grammar/fixtures/text.astro b/packages/vscode/test/grammar/fixtures/text.astro index d731651a..96b1ca80 100644 --- a/packages/vscode/test/grammar/fixtures/text.astro +++ b/packages/vscode/test/grammar/fixtures/text.astro @@ -1,4 +1,15 @@ -text
text
-
text
text -text{"text"} -{"text"}text \ No newline at end of file +--- +const cool = "our frontmatter" +console.log("Hello, World!") +console.log(`This is ${cool}!`) +--- + +This is some text
+

+ Some text in HTML tags + and some text in nested tags +

+ Watch this   html entity! + {true &&

Some more text in expression

} + +
This is the final text \ No newline at end of file diff --git a/packages/vscode/test/grammar/fixtures/text.astro.snap b/packages/vscode/test/grammar/fixtures/text.astro.snap index 15aaf82a..bb904ba9 100644 --- a/packages/vscode/test/grammar/fixtures/text.astro.snap +++ b/packages/vscode/test/grammar/fixtures/text.astro.snap @@ -1,28 +1,58 @@ ->text
text
+>--- +#^^^ source.astro comment +>const cool = "our frontmatter" +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.ts +>console.log("Hello, World!") +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.ts +>console.log(`This is ${cool}!`) +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.ts +>--- +#^^^ source.astro comment +> +>This is some text
+#^^^^^^^^^^^^^^^^^ source.astro text.astro +# ^ source.astro meta.scope.tag.div.astro meta.tag.start.astro punctuation.definition.tag.begin.astro +# ^^^ source.astro meta.scope.tag.div.astro meta.tag.start.astro entity.name.tag.astro +# ^ source.astro meta.scope.tag.div.astro meta.tag.start.astro punctuation.definition.tag.end.astro +>

+#^^ source.astro text.astro +# ^ source.astro meta.scope.tag.p.astro meta.tag.start.astro punctuation.definition.tag.begin.astro +# ^ source.astro meta.scope.tag.p.astro meta.tag.start.astro entity.name.tag.astro +# ^ source.astro meta.scope.tag.p.astro meta.tag.start.astro punctuation.definition.tag.end.astro +> Some text in HTML tags +#^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro text.astro +> and some text in nested tags #^^^^ source.astro text.astro -# ^ source.astro meta.scope.tag.div.astro meta.tag.start.astro punctuation.definition.tag.begin.astro -# ^^^ source.astro meta.scope.tag.div.astro meta.tag.start.astro entity.name.tag.astro -# ^ source.astro meta.scope.tag.div.astro meta.tag.start.astro punctuation.definition.tag.end.astro -# ^^^^ source.astro text.astro -# ^^ source.astro meta.scope.tag.div.astro meta.tag.end.astro punctuation.definition.tag.begin.astro -# ^^^ source.astro meta.scope.tag.div.astro meta.tag.end.astro entity.name.tag.astro -# ^ source.astro meta.scope.tag.div.astro meta.tag.end.astro punctuation.definition.tag.end.astro ->

text
text -#^ source.astro meta.scope.tag.div.astro meta.tag.start.astro punctuation.definition.tag.begin.astro -# ^^^ source.astro meta.scope.tag.div.astro meta.tag.start.astro entity.name.tag.astro -# ^ source.astro meta.scope.tag.div.astro meta.tag.start.astro punctuation.definition.tag.end.astro -# ^^^^ source.astro text.astro -# ^^ source.astro meta.scope.tag.div.astro meta.tag.end.astro punctuation.definition.tag.begin.astro -# ^^^ source.astro meta.scope.tag.div.astro meta.tag.end.astro entity.name.tag.astro -# ^ source.astro meta.scope.tag.div.astro meta.tag.end.astro punctuation.definition.tag.end.astro -# ^^^^ source.astro text.astro ->text{"text"} -#^^^^ source.astro text.astro -# ^ source.astro punctuation.section.embedded.begin.astro -# ^^^^^^ source.astro meta.embedded.expression.astro source.tsx -# ^ source.astro punctuation.section.embedded.end.astro ->{"text"}text -#^ source.astro punctuation.section.embedded.begin.astro -# ^^^^^^ source.astro meta.embedded.expression.astro source.tsx -# ^ source.astro punctuation.section.embedded.end.astro -# ^^^^ source.astro text.astro \ No newline at end of file +# ^ source.astro meta.scope.tag.strong.astro meta.tag.start.astro punctuation.definition.tag.begin.astro +# ^^^^^^ source.astro meta.scope.tag.strong.astro meta.tag.start.astro entity.name.tag.astro +# ^ source.astro meta.scope.tag.strong.astro meta.tag.start.astro punctuation.definition.tag.end.astro +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro text.astro +# ^^ source.astro meta.scope.tag.strong.astro meta.tag.end.astro punctuation.definition.tag.begin.astro +# ^^^^^^ source.astro meta.scope.tag.strong.astro meta.tag.end.astro entity.name.tag.astro +# ^ source.astro meta.scope.tag.strong.astro meta.tag.end.astro punctuation.definition.tag.end.astro +>

+#^^ source.astro text.astro +# ^^ source.astro meta.scope.tag.p.astro meta.tag.end.astro punctuation.definition.tag.begin.astro +# ^ source.astro meta.scope.tag.p.astro meta.tag.end.astro entity.name.tag.astro +# ^ source.astro meta.scope.tag.p.astro meta.tag.end.astro punctuation.definition.tag.end.astro +> Watch this   html entity! +#^^^^^^^^^^^^^ source.astro text.astro +# ^ source.astro text.astro constant.character.entity.named.nbsp.astro punctuation.definition.entity.astro +# ^^^^ source.astro text.astro constant.character.entity.named.nbsp.astro +# ^ source.astro text.astro constant.character.entity.named.nbsp.astro punctuation.definition.entity.astro +# ^^^^^^^^^^^^^ source.astro text.astro +> {true &&

Some more text in expression

} +#^^ source.astro text.astro +# ^ source.astro punctuation.section.embedded.begin.astro +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro meta.embedded.expression.astro source.tsx +# ^ source.astro punctuation.section.embedded.end.astro +> +#^^ source.astro text.astro +# ^^^^ source.astro comment.block.astro punctuation.definition.comment.astro +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro comment.block.astro +# ^^^ source.astro comment.block.astro punctuation.definition.comment.astro +>
This is the final text +#^^ source.astro meta.scope.tag.div.astro meta.tag.end.astro punctuation.definition.tag.begin.astro +# ^^^ source.astro meta.scope.tag.div.astro meta.tag.end.astro entity.name.tag.astro +# ^ source.astro meta.scope.tag.div.astro meta.tag.end.astro punctuation.definition.tag.end.astro +# ^^^^^^^^^^^^^^^^^^^^^^ source.astro text.astro \ No newline at end of file