Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix vscode-graphql-syntax’s grammar to support string literals on separate lines #3518

Merged
merged 14 commits into from Mar 1, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/famous-games-begin.md
@@ -0,0 +1,5 @@
---
'vscode-graphql-syntax': patch
---

Fix Textmate grammar to support string literals that don’t immediately follow a function call paranthesis (`(`).
kitten marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 23 additions & 26 deletions packages/vscode-graphql-syntax/grammars/graphql.js.json
Expand Up @@ -4,39 +4,33 @@
"patterns": [
{
"contentName": "meta.embedded.block.graphql",
"begin": "\\s*+(?:(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental)|(/\\* GraphQL \\*/))\\s*\\(?\\s*(`|'|\")",
"beginCaptures": {
"1": {
"name": "variable.other.class.js"
},
"2": {
"name": "entity.name.function.tagged-template.js"
},
"3": {
"name": "entity.name.function.tagged-template.js"
},
"4": {
"name": "comment.graphql.js"
},
"5": {
"name": "punctuation.definition.string.template.begin.js"
}
},
"end": "(`|'|\")",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.template.end.js"
}
},
"begin": "(?<=(?:(?:Relay\\??\\.)QL|gql|graphql|graphql\\.experimental)\\s*(?:<.*>)?\\s*)\\(",
"end": "\\)",
"patterns": [
{
"include": "source.graphql"
"begin": "(`|'|\")",
"end": "(`|'|\")",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.template.begin.js"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.string.template.end.js"
}
},
"patterns": [
{
"include": "source.graphql"
}
]
}
]
},
{
"contentName": "meta.embedded.block.graphql",
"begin": "\\s*+(?:(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental))\\s*\\(?\\s*(?:<.*>)(`|'|\")",
"begin": "\\s*+(?:(?:(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental)\\s*(?:<.*>)?\\s*)|(/\\* GraphQL \\*/))\\s*(`|'|\")",
"beginCaptures": {
"1": {
"name": "variable.other.class.js"
Expand All @@ -48,6 +42,9 @@
"name": "entity.name.function.tagged-template.js"
},
"4": {
"name": "comment.graphql.js"
},
"5": {
"name": "punctuation.definition.string.template.begin.js"
}
},
Expand Down
11 changes: 10 additions & 1 deletion packages/vscode-graphql-syntax/tests/__fixtures__/test.js
Expand Up @@ -36,8 +36,18 @@ const graphql = graphql(`
}
`);

const graphql = graphql(
`
query { test }
`,
[var1, var2]
);

const query = /* GraphQL */ 'query { id } ';
const query = graphql('query { id } ');
const query = graphql(
'query { id } '
);

const queryWithInlineComment = `#graphql
query {
Expand All @@ -58,7 +68,6 @@ const queryWithInlineComment = `#graphql
}
}
`;
// TODO: fix this
const queryWithInlineComment = `
#graphql
query {
Expand Down
20 changes: 19 additions & 1 deletion packages/vscode-graphql-syntax/tests/__fixtures__/test.ts
Expand Up @@ -25,9 +25,27 @@ const query = graphql<SomeGeneric>`
}
`;

// TODO: Fix this
const query = graphql<Generic>('query { id }');

const query = graphql(
'query { id }'
);

const query = graphql<Generic>(
'query { id }'
);

const query = graphql(`
query { id }
`);

const query = graphql(
`
query { id }
`,
[var1, var2]
);

const queryWithInlineComment = `#graphql
query {
user(id: "5", name: boolean) {
Expand Down