on master help sign in
feat(languages): GraphQL (#1515)

* Add Graphql language support * Fix docs gen * Add JS Graphql injection query * Updates based on PR feedback Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>

commit0b55b21f3069640d37d2fa34bd413986177c0cd7 authorJared Ramirez <jaredramirez@hey.com> dateFri 21 Jan 2022, 06:16 (5 years ago) parentf453f87
6 files changed+185
.gitmodules+4 book/src/generated/lang-support.md+1 helix-syntax/languages/tree-sitter-graphql+1 languages.toml+8 runtime/queries/graphql/highlights.scm+163 runtime/queries/javascript/injections.scm+8
.gitmodules+4
@@ -206,6 +206,10 @@
206206 path = helix-syntax/languages/tree-sitter-git-config
207207 url = https://github.com/the-mikedavis/tree-sitter-git-config.git
208208 shallow = true
209+[submodule "helix-syntax/languages/tree-sitter-graphql"]
210+ path = helix-syntax/languages/tree-sitter-graphql
211+ url = https://github.com/bkegley/tree-sitter-graphql
212+ shallow = true
209213[submodule "helix-syntax/languages/tree-sitter-elm"]
210214 path = helix-syntax/languages/tree-sitter-elm
211215 url = https://github.com/elm-tooling/tree-sitter-elm
book/src/generated/lang-support.md+1
@@ -18,6 +18,7 @@
1818| git-rebase | ✓ | | | |
1919| glsl | ✓ | | ✓ | |
2020| go | ✓ | ✓ | ✓ | `gopls` |
21+| graphql | ✓ | | | |
2122| haskell | ✓ | | | |
2223| html | ✓ | | | |
2324| java | ✓ | | | |
helix-syntax/languages/tree-sitter-graphqlnew file+1

Submodule changed.

languages.toml+8
@@ -568,6 +568,14 @@ injection-regex = "git-config"
568568comment-token = "#"
569569indent = { tab-width = 4, unit = "\t" }
570570
571+[[language]]
572+name = "graphql"
573+scope = "source.graphql"
574+injection-regex = "graphql"
575+file-types = ["gql", "graphql"]
576+roots = []
577+indent = { tab-width = 2, unit = " " }
578+
571579[[language]]
572580name = "elm"
573581scope = "source.elm"
runtime/queries/graphql/highlights.scmnew file+163
@@ -0,0 +1,163 @@
1+; Types
2+;------
3+
4+(scalar_type_definition
5+ (name) @type)
6+
7+(object_type_definition
8+ (name) @type)
9+
10+(interface_type_definition
11+ (name) @type)
12+
13+(union_type_definition
14+ (name) @type)
15+
16+(enum_type_definition
17+ (name) @type)
18+
19+(input_object_type_definition
20+ (name) @type)
21+
22+(directive_definition
23+ (name) @type)
24+
25+(directive_definition
26+ "@" @type)
27+
28+(scalar_type_extension
29+ (name) @type)
30+
31+(object_type_extension
32+ (name) @type)
33+
34+(interface_type_extension
35+ (name) @type)
36+
37+(union_type_extension
38+ (name) @type)
39+
40+(enum_type_extension
41+ (name) @type)
42+
43+(input_object_type_extension
44+ (name) @type)
45+
46+(named_type
47+ (name) @type)
48+
49+(directive) @type
50+
51+; Properties
52+;-----------
53+
54+(field
55+ (name) @variable.other.member)
56+
57+(field
58+ (alias
59+ (name) @variable.other.member))
60+
61+(field_definition
62+ (name) @variable.other.member)
63+
64+(object_value
65+ (object_field
66+ (name) @variable.other.member))
67+
68+(enum_value
69+ (name) @variable.other.member)
70+
71+; Variable Definitions and Arguments
72+;-----------------------------------
73+
74+(operation_definition
75+ (name) @variable)
76+
77+(fragment_name
78+ (name) @variable)
79+
80+(input_fields_definition
81+ (input_value_definition
82+ (name) @variable.parameter))
83+
84+(argument
85+ (name) @variable.parameter)
86+
87+(arguments_definition
88+ (input_value_definition
89+ (name) @variable.parameter))
90+
91+(variable_definition
92+ (variable) @variable.parameter)
93+
94+(argument
95+ (value
96+ (variable) @variable))
97+
98+; Constants
99+;----------
100+
101+(string_value) @string
102+
103+(int_value) @constants.numeric.integer
104+
105+(float_value) @constants.numeric.float
106+
107+(boolean_value) @constants.builtin.boolean
108+
109+; Literals
110+;---------
111+
112+(description) @comment
113+
114+(comment) @comment
115+
116+(directive_location
117+ (executable_directive_location) @type.builtin)
118+
119+(directive_location
120+ (type_system_directive_location) @type.builtin)
121+
122+; Keywords
123+;----------
124+
125+[
126+ "query"
127+ "mutation"
128+ "subscription"
129+ "fragment"
130+ "scalar"
131+ "type"
132+ "interface"
133+ "union"
134+ "enum"
135+ "input"
136+ "extend"
137+ "directive"
138+ "schema"
139+ "on"
140+ "repeatable"
141+ "implements"
142+] @keyword
143+
144+; Punctuation
145+;------------
146+
147+[
148+ "("
149+ ")"
150+ "["
151+ "]"
152+ "{"
153+ "}"
154+] @punctuation.bracket
155+
156+"=" @operator
157+
158+"|" @punctuation.delimiter
159+"&" @punctuation.delimiter
160+":" @punctuation.delimiter
161+
162+"..." @punctuation.special
163+"!" @punctuation.special
runtime/queries/javascript/injections.scm+8
@@ -9,6 +9,14 @@
99 ]
1010 arguments: (template_string) @injection.content)
1111
12+; Parse the contents of gql template literals
13+
14+((call_expression
15+ function: (identifier) @_template_function_name
16+ arguments: (template_string) @injection.content)
17+ (#eq? @_template_function_name "gql")
18+ (#set! injection.language "graphql"))
19+
1220; Parse regex syntax within regex literals
1321
1422((regex_pattern) @injection.content