Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-ears-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro-vscode': patch
---

Fixes syntax highlighting sometimes not working when the frontmatter or script tags ended with certain TypeScript constructs
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}/tools/vscode"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea where this config came from, but it didn't work for the merge so I fixed it

"outFiles": ["${workspaceRoot}/tools/vscode/dist/**/*.js"]
"args": ["--extensionDevelopmentPath=${workspaceRoot}/packages/language-tools/vscode"],
"outFiles": ["${workspaceRoot}/*/*/dist/**/*.js"]
},
{
"name": "Attach to Server",
"type": "node",
"request": "attach",
"name": "Attach to Server",
"port": 6040,
"port": 6009,
"restart": true,
"outFiles": ["${workspaceRoot}/tools/languageserver/dist/**/*.js"],
"outFiles": ["${workspaceRoot}/*/*/dist/**/*.js"],
"skipFiles": ["<node_internals>/**"]
}
],
Expand All @@ -26,4 +26,4 @@
"configurations": ["Launch Client", "Attach to Server"]
}
]
}
}
67 changes: 60 additions & 7 deletions packages/language-tools/vscode/syntaxes/astro.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "Astro",
"scopeName": "source.astro",
"fileTypes": ["astro"],
"fileTypes": [
"astro"
],
"injections": {
"L:(meta.script.astro) (meta.lang.json) - (meta source)": {
"patterns": [
Expand All @@ -20,9 +22,20 @@
},
"L:(meta.script.astro) (meta.lang.js | meta.lang.javascript | meta.lang.partytown | meta.lang.node) - (meta source)": {
"patterns": [
{
"begin": "(?<=>)(?=[^\\n]+</script[\\s>])",
"end": "(?=</script[\\s>])",
"name": "meta.embedded.block.astro",
"contentName": "source.js",
"patterns": [
{
"include": "source.js"
}
]
},
{
"begin": "(?<=>)(?!</)",
"end": "(?=</)",
"while": "^(?!\\s*</script[\\s>])",
"name": "meta.embedded.block.astro",
"contentName": "source.js",
"patterns": [
Expand All @@ -35,9 +48,20 @@
},
"L:(meta.script.astro) (meta.lang.ts | meta.lang.typescript) - (meta source)": {
"patterns": [
{
"begin": "(?<=>)(?=[^\\n]+</script[\\s>])",
"end": "(?=</script[\\s>])",
"name": "meta.embedded.block.astro",
"contentName": "source.ts",
"patterns": [
{
"include": "source.ts"
}
]
},
{
"begin": "(?<=>)(?!</)",
"end": "(?=</)",
"while": "^(?!\\s*</script[\\s>])",
"name": "meta.embedded.block.astro",
"contentName": "source.ts",
"patterns": [
Expand All @@ -50,9 +74,20 @@
},
"L:meta.script.astro - meta.lang - (meta source)": {
"patterns": [
{
"begin": "(?<=>)(?=[^\\n]+</script[\\s>])",
"end": "(?=</script[\\s>])",
"name": "meta.embedded.block.astro",
"contentName": "source.js",
"patterns": [
{
"include": "source.js"
}
]
},
{
"begin": "(?<=>)(?!</)",
"end": "(?=</)",
"while": "^(?!\\s*</script[\\s>])",
"name": "meta.embedded.block.astro",
"contentName": "source.js",
"patterns": [
Expand Down Expand Up @@ -194,10 +229,28 @@
"name": "comment"
}
},
"contentName": "source.ts",
"patterns": [
{
"include": "source.ts"
"begin": "(?<=\\n)(?=[^\\n]+^-{3})",
"end": "(?=^-{3})",
"name": "meta.embedded.block.astro",
"contentName": "source.ts",
"patterns": [
{
"include": "source.ts"
}
]
},
{
"begin": "(?<=\\n)",
"while": "^(?!\\s*-{3})",
"name": "meta.embedded.block.astro",
"contentName": "source.ts",
"patterns": [
{
"include": "source.ts"
}
]
}
]
},
Expand Down Expand Up @@ -841,4 +894,4 @@
]
}
}
}
}
55 changes: 43 additions & 12 deletions packages/language-tools/vscode/syntaxes/astro.tmLanguage.src.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ injections:

# JavaScript | 'javascript' | 'source.js' | 'partytown'
'L:(meta.script.astro) (meta.lang.js | meta.lang.javascript | meta.lang.partytown | meta.lang.node) - (meta source)':
patterns:
[
patterns: [
{
begin: '(?<=>)(?=[^\n]+</script[\s>])',
end: '(?=</script[\s>])',
name: meta.embedded.block.astro,
contentName: source.js,
patterns: [{ include: source.js }],
},
{
begin: '(?<=>)(?!</)',
end: '(?=</)',
while: '^(?!\s*</script[\s>])',
name: meta.embedded.block.astro,
contentName: source.js,
patterns: [{ include: source.js }],
Expand All @@ -42,11 +48,17 @@ injections:

# TypeScript | 'ts'
'L:(meta.script.astro) (meta.lang.ts | meta.lang.typescript) - (meta source)':
patterns:
[
patterns: [
{
begin: '(?<=>)(?=[^\n]+</script[\s>])',
end: '(?=</script[\s>])',
name: meta.embedded.block.astro,
contentName: source.ts,
patterns: [{ include: source.ts }],
},
{
begin: '(?<=>)(?!</)',
end: '(?=</)',
while: '^(?!\s*</script[\s>])',
name: meta.embedded.block.astro,
contentName: source.ts,
patterns: [{ include: source.ts }],
Expand All @@ -56,11 +68,17 @@ injections:
# Script Languages
# Default (JavaScript)
'L:meta.script.astro - meta.lang - (meta source)':
patterns:
[
patterns: [
{
begin: '(?<=>)(?=[^\n]+</script[\s>])',
end: '(?=</script[\s>])',
name: meta.embedded.block.astro,
contentName: source.js,
patterns: [{ include: source.js }],
},
{
begin: '(?<=>)(?!</)',
end: '(?=</)',
while: '^(?!\s*</script[\s>])',
name: meta.embedded.block.astro,
contentName: source.js,
patterns: [{ include: source.js }],
Expand Down Expand Up @@ -180,9 +198,22 @@ repository:
1: { name: comment }
endCaptures:
2: { name: comment }
contentName: source.ts
patterns:
- include: source.ts
patterns: [
{
begin: '(?<=\n)(?=[^\n]+^-{3})',
end: '(?=^-{3})',
name: meta.embedded.block.astro,
contentName: source.ts,
patterns: [{ include: source.ts }],
},
{
begin: '(?<=\n)',
while: '^(?!\s*-{3})',
name: meta.embedded.block.astro,
contentName: source.ts,
patterns: [{ include: source.ts }],
},
]

# -------
# SCOPE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
>---
#^^^ source.astro comment
>const cool = "our frontmatter"
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.ts
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro meta.embedded.block.astro source.ts
>console.log("Hello, World!")
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.ts
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro meta.embedded.block.astro source.ts
>console.log(`This is ${cool}!`)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro source.ts
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro meta.embedded.block.astro source.ts
>---
#^^^ source.astro comment
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
type Something = "Hello"
---

<script>
type Something = "Hello"
</script>

<div></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
>---
#^^^ source.astro comment
>type Something = "Hello"
#^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro meta.embedded.block.astro source.ts
>---
#^^^ source.astro comment
>
><script>
#^ source.astro meta.scope.tag.script.astro meta.script.astro meta.tag.start.astro punctuation.definition.tag.begin.astro
# ^^^^^^ source.astro meta.scope.tag.script.astro meta.script.astro meta.tag.start.astro entity.name.tag.astro
# ^ source.astro meta.scope.tag.script.astro meta.script.astro meta.tag.start.astro punctuation.definition.tag.end.astro
>type Something = "Hello"
#^^^^^^^^^^^^^^^^^^^^^^^^^ source.astro meta.scope.tag.script.astro meta.script.astro meta.embedded.block.astro source.js
></script>
#^^ source.astro meta.scope.tag.script.astro meta.script.astro meta.tag.end.astro punctuation.definition.tag.begin.astro
# ^^^^^^ source.astro meta.scope.tag.script.astro meta.script.astro meta.tag.end.astro entity.name.tag.astro
# ^ source.astro meta.scope.tag.script.astro meta.script.astro meta.tag.end.astro punctuation.definition.tag.end.astro
>
><div></div>
#^ 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 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