Skip to content

Commit

Permalink
Add Python support to the editor plugin (#694)
Browse files Browse the repository at this point in the history
This depends on the language server supporting Python (PR #693) for IntelliSense.

Apollo config defaults to JS/TS files only, so it's required to add `*.py` to
`apollo.config.js` under `client.includes` before completion/validation starts
to work.
  • Loading branch information
patrys authored and martijnwalraven committed Nov 13, 2018
1 parent 5f3fb63 commit a1255bc
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/vscode-apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
5 changes: 3 additions & 2 deletions packages/vscode-apollo/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
]
}
};
Expand Down
57 changes: 57 additions & 0 deletions packages/vscode-apollo/syntaxes/graphql.py.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit a1255bc

Please sign in to comment.