From 3c79f802e51914cde8edd8844535a11e55b742dc Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Fri, 14 Jan 2022 16:20:45 -0600 Subject: [PATCH 1/4] Add Graphql language support --- .gitmodules | 4 + helix-syntax/languages/tree-sitter-graphql | 1 + languages.toml | 8 + runtime/queries/graphql/highlights.scm | 163 +++++++++++++++++++++ 4 files changed, 176 insertions(+) create mode 160000 helix-syntax/languages/tree-sitter-graphql create mode 100644 runtime/queries/graphql/highlights.scm diff --git a/.gitmodules b/.gitmodules index 3442652a65a2..5d6e6ffb7f17 100644 --- a/.gitmodules +++ b/.gitmodules @@ -202,3 +202,7 @@ 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 diff --git a/helix-syntax/languages/tree-sitter-graphql b/helix-syntax/languages/tree-sitter-graphql new file mode 160000 index 000000000000..5e66e961eee4 --- /dev/null +++ b/helix-syntax/languages/tree-sitter-graphql @@ -0,0 +1 @@ +Subproject commit 5e66e961eee421786bdda8495ed1db045e06b5fe diff --git a/languages.toml b/languages.toml index 2c870ab24c0d..40d69ab2d273 100644 --- a/languages.toml +++ b/languages.toml @@ -555,3 +555,11 @@ file-types = [".gitmodules", ".gitconfig"] 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 = " " } diff --git a/runtime/queries/graphql/highlights.scm b/runtime/queries/graphql/highlights.scm new file mode 100644 index 000000000000..03e434f87895 --- /dev/null +++ b/runtime/queries/graphql/highlights.scm @@ -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) @label) + +(field + (alias + (name) @label)) + +(field_definition + (name) @label) + +(object_value + (object_field + (name) @label)) + +(enum_value + (name) @label) + +; 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 From 194f46c11a1871c916ea1174397cbbf2d588ecc2 Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Sat, 15 Jan 2022 12:21:28 -0800 Subject: [PATCH 2/4] Fix docs gen --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 8b599f6b4dc7..2e5b4a3e5670 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -17,6 +17,7 @@ | git-rebase | ✓ | | | | | glsl | ✓ | | ✓ | | | go | ✓ | ✓ | ✓ | `gopls` | +| graphql | ✓ | | | | | html | ✓ | | | | | java | ✓ | | | | | javascript | ✓ | | ✓ | `typescript-language-server` | From f8f42076e6465c3d86526b4434d3e361a4ec37c1 Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Sat, 15 Jan 2022 16:56:24 -0800 Subject: [PATCH 3/4] Add JS Graphql injection query --- runtime/queries/javascript/injections.scm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/runtime/queries/javascript/injections.scm b/runtime/queries/javascript/injections.scm index 5539241a68d8..5522a19b0c0a 100644 --- a/runtime/queries/javascript/injections.scm +++ b/runtime/queries/javascript/injections.scm @@ -9,6 +9,14 @@ ] arguments: (template_string) @injection.content) +; Parse the contents of gql template literals + +((call_expression + function: (identifier) @ignore + arguments: (template_string) @injection.content) + (#eq? @ignore "gql") + (#set! injection.language "graphql")) + ; Parse regex syntax within regex literals ((regex_pattern) @injection.content From 9fb807be930cab3ce838105a5b30e2ad3d99d324 Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Mon, 17 Jan 2022 09:31:35 -0800 Subject: [PATCH 4/4] Updates based on PR feedback --- runtime/queries/graphql/highlights.scm | 10 +++++----- runtime/queries/javascript/injections.scm | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/queries/graphql/highlights.scm b/runtime/queries/graphql/highlights.scm index 03e434f87895..9fab40515cd9 100644 --- a/runtime/queries/graphql/highlights.scm +++ b/runtime/queries/graphql/highlights.scm @@ -52,21 +52,21 @@ ;----------- (field - (name) @label) + (name) @variable.other.member) (field (alias - (name) @label)) + (name) @variable.other.member)) (field_definition - (name) @label) + (name) @variable.other.member) (object_value (object_field - (name) @label)) + (name) @variable.other.member)) (enum_value - (name) @label) + (name) @variable.other.member) ; Variable Definitions and Arguments ;----------------------------------- diff --git a/runtime/queries/javascript/injections.scm b/runtime/queries/javascript/injections.scm index 5522a19b0c0a..e84291115dae 100644 --- a/runtime/queries/javascript/injections.scm +++ b/runtime/queries/javascript/injections.scm @@ -12,9 +12,9 @@ ; Parse the contents of gql template literals ((call_expression - function: (identifier) @ignore + function: (identifier) @_template_function_name arguments: (template_string) @injection.content) - (#eq? @ignore "gql") + (#eq? @_template_function_name "gql") (#set! injection.language "graphql")) ; Parse regex syntax within regex literals