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 [Reapply & Fix] #3545

Merged
merged 4 commits into from Mar 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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's left-parenthesis (`(`).
48 changes: 32 additions & 16 deletions packages/vscode-graphql-syntax/grammars/graphql.js.json
Expand Up @@ -3,8 +3,8 @@
"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": "\\s*+(?:(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental)|(/\\* GraphQL \\*/))\\s*\\(?\\s*(`|')",
"begin": "\\s*+(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental)\\s*(?:<.*>)?\\s*\\(",
"end": "\\)",
"beginCaptures": {
"1": {
"name": "variable.other.class.js"
Expand All @@ -14,29 +14,42 @@
},
"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"
}
},
"patterns": [
{
"include": "source.graphql"
"contentName": "meta.embedded.block.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"
}
]
},
{
"patterns": [
{ "include": "source.js" },
{ "include": "source.ts" },
{ "include": "source.js.jsx" },
{ "include": "source.tsx" }
]
}
]
},
{
"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 +61,9 @@
"name": "entity.name.function.tagged-template.js"
},
"4": {
"name": "comment.graphql.js"
},
"5": {
"name": "punctuation.definition.string.template.begin.js"
}
},
Expand Down
17 changes: 15 additions & 2 deletions packages/vscode-graphql-syntax/tests/__fixtures__/test.js
Expand Up @@ -37,8 +37,22 @@ const graphql = graphql(`
}
`);

const after1 = 'after';

const graphql = graphql(
`
query($id: ID!) { test }
`,
[var1, var2]
);

const after2 = 'after';

const query = /* GraphQL */ 'query { id } ';
const query = graphql('query { id } ');
const query = graphql('query($id: ID!) { id } ');
const query = graphql(
'query($id: ID!) { test }'
);

const queryWithInlineComment = `#graphql
query {
Expand All @@ -59,7 +73,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