Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(languages): GraphQL #1515

Merged
merged 6 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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