Skip to content

Commit

Permalink
Remove lookbehind in grammar and add inner TS/JS source patterns
Browse files Browse the repository at this point in the history
Using a positive lookbehind can subtly break Textmate/VSCode’s syntax
highlighting. The positive lookbehind (according to some online sources)
can fail unexpectedly when they contain whitespace matches.

This means that we should instead match explicitly, like the other
patterns do. This means however, that we might match too much and
I noticed that arguments to the function aren't highlighted correctly.

According to the interpolation rule in `graphql.json` we now include
patterns for JS/TS/etc as a fallback pattern.

This fixes the issue and prevents the case where the rule was
conflicting with normal JS/TS patterns in a different tmLanguage
grammar.
  • Loading branch information
kitten committed Mar 2, 2024
1 parent cf45224 commit d1bf2b6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/vscode-graphql-syntax/grammars/graphql.js.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
"injectionSelector": "L:(meta.embedded.block.javascript | meta.embedded.block.typescript | source.js | source.ts | source.tsx | source.vue | source.svelte | source.astro) -source.graphql -inline.graphql -string -comment",
"patterns": [
{
"contentName": "meta.embedded.block.graphql",
"begin": "(?<=(?:(?:Relay\\??\\.)QL|gql|graphql|graphql\\.experimental)\\s*(?:<.*>)?\\s*)\\(",
"begin": "\\s*+(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental)\\s*(?:<.*>)?\\s*\\(",
"end": "\\)",
"beginCaptures": {
"1": {
"name": "variable.other.class.js"
},
"2": {
"name": "entity.name.function.tagged-template.js"
},
"3": {
"name": "entity.name.function.tagged-template.js"
}
},
"patterns": [
{
"contentName": "meta.embedded.block.graphql",
"begin": "(`|')",
"end": "(`|')",
"beginCaptures": {
Expand All @@ -25,6 +36,14 @@
"include": "source.graphql"
}
]
},
{
"patterns": [
{ "include": "source.js" },
{ "include": "source.ts" },
{ "include": "source.js.jsx" },
{ "include": "source.tsx" }
]
}
]
},
Expand Down

0 comments on commit d1bf2b6

Please sign in to comment.