diff --git a/packages/vscode-apollo/package.json b/packages/vscode-apollo/package.json index 2f8a94cce0..c487505a78 100644 --- a/packages/vscode-apollo/package.json +++ b/packages/vscode-apollo/package.json @@ -88,6 +88,16 @@ "embeddedLanguages": { "meta.embedded.block.graphql": "graphql" } + }, + { + "injectTo": [ + "source.python" + ], + "scopeName": "inline.graphql.python", + "path": "./syntaxes/graphql.py.json", + "embeddedLanguages": { + "meta.embedded.block.graphql": "graphql" + } } ], "commands": [ diff --git a/packages/vscode-apollo/src/extension.ts b/packages/vscode-apollo/src/extension.ts index 44a628d773..cfa68fd0da 100644 --- a/packages/vscode-apollo/src/extension.ts +++ b/packages/vscode-apollo/src/extension.ts @@ -59,13 +59,14 @@ export function activate(context: ExtensionContext) { "javascript", "typescript", "javascriptreact", - "typescriptreact" + "typescriptreact", + "python" ], synchronize: { fileEvents: [ workspace.createFileSystemWatcher("**/apollo.config.js"), workspace.createFileSystemWatcher("**/package.json"), - workspace.createFileSystemWatcher("**/*.{graphql,js,ts,jsx,tsx}") + workspace.createFileSystemWatcher("**/*.{graphql,js,ts,jsx,tsx,py}") ] } }; diff --git a/packages/vscode-apollo/syntaxes/graphql.py.json b/packages/vscode-apollo/syntaxes/graphql.py.json new file mode 100644 index 0000000000..23f22e7a65 --- /dev/null +++ b/packages/vscode-apollo/syntaxes/graphql.py.json @@ -0,0 +1,57 @@ +{ + "fileTypes": ["python"], + "injectionSelector": "L:source -string -comment", + "patterns": [ + { + "name": "meta.function-call.python", + "begin": "\\b(gql)\\s*(\\()", + "beginCaptures": { + "1": { + "name": "meta.function-call.generic.python" + }, + "2": { + "name": "punctuation.definition.arguments.begin.python" + } + }, + "end": "(\\))", + "endCaptures": { + "1": { + "name": "punctuation.definition.arguments.end.python" + } + }, + "patterns": [ + { + "name": "taggedTemplates", + "contentName": "meta.embedded.block.graphql", + "begin": "([bfru]*)((\"(?:\"\")?|'(?:'')?))", + "beginCaptures": { + "1": { + "name": "storage.type.string.python" + }, + "2": { + "name": "string.quoted.multi.python" + }, + "3": { + "name": "punctuation.definition.string.begin.python" + } + }, + "end": "((\\3))", + "endCaptures": { + "1": { + "name": "string.quoted.multi.python" + }, + "2": { + "name": "punctuation.definition.string.end.python" + } + }, + "patterns": [ + { + "include": "source.graphql" + } + ] + } + ] + } + ], + "scopeName": "inline.graphql.python" +}