Skip to content

Commit a1255bc

Browse files
patrysmartijnwalraven
authored andcommitted
Add Python support to the editor plugin (#694)
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.
1 parent 5f3fb63 commit a1255bc

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

packages/vscode-apollo/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@
8888
"embeddedLanguages": {
8989
"meta.embedded.block.graphql": "graphql"
9090
}
91+
},
92+
{
93+
"injectTo": [
94+
"source.python"
95+
],
96+
"scopeName": "inline.graphql.python",
97+
"path": "./syntaxes/graphql.py.json",
98+
"embeddedLanguages": {
99+
"meta.embedded.block.graphql": "graphql"
100+
}
91101
}
92102
],
93103
"commands": [

packages/vscode-apollo/src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ export function activate(context: ExtensionContext) {
5959
"javascript",
6060
"typescript",
6161
"javascriptreact",
62-
"typescriptreact"
62+
"typescriptreact",
63+
"python"
6364
],
6465
synchronize: {
6566
fileEvents: [
6667
workspace.createFileSystemWatcher("**/apollo.config.js"),
6768
workspace.createFileSystemWatcher("**/package.json"),
68-
workspace.createFileSystemWatcher("**/*.{graphql,js,ts,jsx,tsx}")
69+
workspace.createFileSystemWatcher("**/*.{graphql,js,ts,jsx,tsx,py}")
6970
]
7071
}
7172
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"fileTypes": ["python"],
3+
"injectionSelector": "L:source -string -comment",
4+
"patterns": [
5+
{
6+
"name": "meta.function-call.python",
7+
"begin": "\\b(gql)\\s*(\\()",
8+
"beginCaptures": {
9+
"1": {
10+
"name": "meta.function-call.generic.python"
11+
},
12+
"2": {
13+
"name": "punctuation.definition.arguments.begin.python"
14+
}
15+
},
16+
"end": "(\\))",
17+
"endCaptures": {
18+
"1": {
19+
"name": "punctuation.definition.arguments.end.python"
20+
}
21+
},
22+
"patterns": [
23+
{
24+
"name": "taggedTemplates",
25+
"contentName": "meta.embedded.block.graphql",
26+
"begin": "([bfru]*)((\"(?:\"\")?|'(?:'')?))",
27+
"beginCaptures": {
28+
"1": {
29+
"name": "storage.type.string.python"
30+
},
31+
"2": {
32+
"name": "string.quoted.multi.python"
33+
},
34+
"3": {
35+
"name": "punctuation.definition.string.begin.python"
36+
}
37+
},
38+
"end": "((\\3))",
39+
"endCaptures": {
40+
"1": {
41+
"name": "string.quoted.multi.python"
42+
},
43+
"2": {
44+
"name": "punctuation.definition.string.end.python"
45+
}
46+
},
47+
"patterns": [
48+
{
49+
"include": "source.graphql"
50+
}
51+
]
52+
}
53+
]
54+
}
55+
],
56+
"scopeName": "inline.graphql.python"
57+
}

0 commit comments

Comments
 (0)