Skip to content

Commit

Permalink
feat(languages): GraphQL (#1515)
Browse files Browse the repository at this point in the history
* Add Graphql language support

* Fix docs gen

* Add JS Graphql injection query

* Updates based on PR feedback

Co-authored-by: Blaž Hrastnik <[email protected]>
  • Loading branch information
Jared Ramirez and archseer authored Jan 21, 2022
1 parent f453f87 commit 0b55b21
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
path = helix-syntax/languages/tree-sitter-git-config
url = https://github.com/the-mikedavis/tree-sitter-git-config.git
shallow = true
[submodule "helix-syntax/languages/tree-sitter-graphql"]
path = helix-syntax/languages/tree-sitter-graphql
url = https://github.com/bkegley/tree-sitter-graphql
shallow = true
[submodule "helix-syntax/languages/tree-sitter-elm"]
path = helix-syntax/languages/tree-sitter-elm
url = https://github.com/elm-tooling/tree-sitter-elm
Expand Down
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
| git-rebase || | | |
| glsl || || |
| go |||| `gopls` |
| graphql || | | |
| haskell || | | |
| html || | | |
| java || | | |
Expand Down
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-graphql
Submodule tree-sitter-graphql added at 5e66e9
8 changes: 8 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ injection-regex = "git-config"
comment-token = "#"
indent = { tab-width = 4, unit = "\t" }

[[language]]
name = "graphql"
scope = "source.graphql"
injection-regex = "graphql"
file-types = ["gql", "graphql"]
roots = []
indent = { tab-width = 2, unit = " " }

[[language]]
name = "elm"
scope = "source.elm"
Expand Down
163 changes: 163 additions & 0 deletions runtime/queries/graphql/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
; Types
;------

(scalar_type_definition
(name) @type)

(object_type_definition
(name) @type)

(interface_type_definition
(name) @type)

(union_type_definition
(name) @type)

(enum_type_definition
(name) @type)

(input_object_type_definition
(name) @type)

(directive_definition
(name) @type)

(directive_definition
"@" @type)

(scalar_type_extension
(name) @type)

(object_type_extension
(name) @type)

(interface_type_extension
(name) @type)

(union_type_extension
(name) @type)

(enum_type_extension
(name) @type)

(input_object_type_extension
(name) @type)

(named_type
(name) @type)

(directive) @type

; Properties
;-----------

(field
(name) @variable.other.member)

(field
(alias
(name) @variable.other.member))

(field_definition
(name) @variable.other.member)

(object_value
(object_field
(name) @variable.other.member))

(enum_value
(name) @variable.other.member)

; Variable Definitions and Arguments
;-----------------------------------

(operation_definition
(name) @variable)

(fragment_name
(name) @variable)

(input_fields_definition
(input_value_definition
(name) @variable.parameter))

(argument
(name) @variable.parameter)

(arguments_definition
(input_value_definition
(name) @variable.parameter))

(variable_definition
(variable) @variable.parameter)

(argument
(value
(variable) @variable))

; Constants
;----------

(string_value) @string

(int_value) @constants.numeric.integer

(float_value) @constants.numeric.float

(boolean_value) @constants.builtin.boolean

; Literals
;---------

(description) @comment

(comment) @comment

(directive_location
(executable_directive_location) @type.builtin)

(directive_location
(type_system_directive_location) @type.builtin)

; Keywords
;----------

[
"query"
"mutation"
"subscription"
"fragment"
"scalar"
"type"
"interface"
"union"
"enum"
"input"
"extend"
"directive"
"schema"
"on"
"repeatable"
"implements"
] @keyword

; Punctuation
;------------

[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket

"=" @operator

"|" @punctuation.delimiter
"&" @punctuation.delimiter
":" @punctuation.delimiter

"..." @punctuation.special
"!" @punctuation.special
8 changes: 8 additions & 0 deletions runtime/queries/javascript/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
]
arguments: (template_string) @injection.content)

; Parse the contents of gql template literals

((call_expression
function: (identifier) @_template_function_name
arguments: (template_string) @injection.content)
(#eq? @_template_function_name "gql")
(#set! injection.language "graphql"))

; Parse regex syntax within regex literals

((regex_pattern) @injection.content
Expand Down

0 comments on commit 0b55b21

Please sign in to comment.