Skip to content

Commit b9f9182

Browse files
author
James Baxley
authored
Merge pull request #1971 from TurtleAI/vscode-elixir-support
Add vscode support for Elixir
2 parents 6e85000 + c5ceb7b commit b9f9182

6 files changed

Lines changed: 92 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
## Upcoming
44

55
- `apollo`
6-
- Fix CLI crashing when trying to open a directory that is named like a file [#1948](https://github.com/apollographql/apollo-tooling/pull/1948).
6+
- <First `apollo` related entry goes here>
77
- `apollo-codegen-flow`
88
- <First `apollo-codegen-flow` related entry goes here>
99
- `apollo-codegen-scala`
1010
- <First `apollo-codegen-scala` related entry goes here>
1111
- `apollo-codegen-swift`
12-
- Change selection sets to computed vars to remove unnecessary memory use [#1950](https://github.com/apollographql/apollo-tooling/pull/1950)
12+
- <First `apollo-codegen-swift` related entry goes here>
1313
- `apollo-codegen-typescript`
1414
- <First `apollo-codegen-typescript` related entry goes here>
1515
- `apollo-codegen-core`
@@ -19,11 +19,11 @@
1919
- `apollo-graphql`
2020
- <First `apollo-graphql` related entry goes here>
2121
- `apollo-language-server`
22-
- <First `apollo-language-server` related entry goes here>
22+
- Add Elixir support for vscode [#1971](https://github.com/apollographql/apollo-tooling/pull/1971)
2323
- `apollo-tools`
2424
- <First `apollo-tools` related entry goes here>
2525
- `vscode-apollo`
26-
- <First `vscode-apollo` related entry goes here>
26+
- Add Elixir support for vscode [#1971](https://github.com/apollographql/apollo-tooling/pull/1971)
2727

2828
## `apollo@2.27.3`
2929

packages/apollo-language-server/src/document.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export function extractGraphQLDocuments(
7474
return extractGraphQLDocumentsFromDartStrings(document, tagName);
7575
case "reason":
7676
return extractGraphQLDocumentsFromReasonStrings(document, tagName);
77+
case "elixir":
78+
return extractGraphQLDocumentsFromElixirStrings(document, tagName);
7779
default:
7880
return null;
7981
}
@@ -228,6 +230,35 @@ function extractGraphQLDocumentsFromReasonStrings(
228230
return documents;
229231
}
230232

233+
function extractGraphQLDocumentsFromElixirStrings(
234+
document: TextDocument,
235+
tagName: string
236+
): GraphQLDocument[] | null {
237+
const text = document.getText();
238+
const documents: GraphQLDocument[] = [];
239+
240+
const regExp = new RegExp(
241+
`\\b(${tagName}\\(\\s*r?("""))([\\s\\S]+?)\\2\\s*\\)`,
242+
"gm"
243+
);
244+
245+
let result;
246+
while ((result = regExp.exec(text)) !== null) {
247+
const contents = replacePlaceholdersWithWhiteSpace(result[3]);
248+
const position = document.positionAt(result.index + result[1].length);
249+
const locationOffset: SourceLocation = {
250+
line: position.line + 1,
251+
column: position.character + 1
252+
};
253+
const source = new Source(contents, document.uri, locationOffset);
254+
documents.push(new GraphQLDocument(source));
255+
}
256+
257+
if (documents.length < 1) return null;
258+
259+
return documents;
260+
}
261+
231262
function replacePlaceholdersWithWhiteSpace(content: string) {
232263
return content.replace(/\$\{([\s\S]+?)\}/gm, match => {
233264
return Array(match.length).join(" ");

packages/apollo-language-server/src/project/base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const fileAssociations: { [extension: string]: string } = {
4444
".py": "python",
4545
".rb": "ruby",
4646
".dart": "dart",
47-
".re": "reason"
47+
".re": "reason",
48+
".ex": "elixir",
49+
".exs": "elixir"
4850
};
4951

5052
export interface GraphQLProjectConfig {

packages/vscode-apollo/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@
133133
"embeddedLanguages": {
134134
"meta.embedded.block.graphql": "graphql"
135135
}
136+
},
137+
{
138+
"injectTo": [
139+
"source.elixir"
140+
],
141+
"scopeName": "inline.graphql.elixir",
142+
"path": "./syntaxes/graphql.ex.json",
143+
"embeddedLanguages": {
144+
"meta.embedded.block.graphql": "graphql"
145+
}
136146
}
137147
],
138148
"commands": [

packages/vscode-apollo/src/languageServerClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ export function getLanguageServerClient(
5050
"python",
5151
"ruby",
5252
"dart",
53-
"reason"
53+
"reason",
54+
"elixir"
5455
],
5556
synchronize: {
5657
fileEvents: [
5758
workspace.createFileSystemWatcher("**/.env?(.local)"),
5859
workspace.createFileSystemWatcher(
59-
"**/*.{graphql,js,ts,jsx,tsx,vue,py,rb,dart,re}"
60+
"**/*.{graphql,js,ts,jsx,tsx,vue,py,rb,dart,re,ex,exs}"
6061
)
6162
]
6263
},
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"fileTypes": [
3+
"ex",
4+
"exs"
5+
],
6+
"injectionSelector": "L:source -string -comment",
7+
"patterns": [
8+
{
9+
"name": "meta.function-call.elixir",
10+
"begin": "\\b(gql)(\\()",
11+
"beginCaptures": {
12+
"1": {
13+
"name": "entity.name.function.elixir"
14+
},
15+
"2": {
16+
"name": "punctuation.definition.arguments.begin.elixir"
17+
}
18+
},
19+
"end": "(\\))",
20+
"endCaptures": {
21+
"1": {
22+
"name": "punctuation.definition.arguments.end.elixir"
23+
}
24+
},
25+
"patterns": [
26+
{
27+
"name": "taggedTemplates",
28+
"contentName": "meta.embedded.block.graphql",
29+
"begin": "r?(\"\"\")",
30+
"end": "((\\1))",
31+
"patterns": [
32+
{
33+
"include": "source.graphql"
34+
}
35+
]
36+
}
37+
]
38+
}
39+
],
40+
"scopeName": "inline.graphql.elixir"
41+
}

0 commit comments

Comments
 (0)