From 2420a8a26bd570494cb787ddfc65c7eb08ffef1f Mon Sep 17 00:00:00 2001 From: Kumar Harsh Date: Sat, 6 Jan 2018 17:15:10 +0400 Subject: [PATCH] feat(syntax): add support for field descriptions. Closes #63 - graphql v0.12.0 has a new proposed way of adding field descriptions as strings rather than comments. See https://github.com/graphql/graphql-js/pull/927. This commit adds support for the usecase. --- syntaxes/graphql.json | 69 ++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/syntaxes/graphql.json b/syntaxes/graphql.json index 0813c56..3b211ea 100644 --- a/syntaxes/graphql.json +++ b/syntaxes/graphql.json @@ -13,6 +13,8 @@ "repository": { "graphql": { "patterns": [ + { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-fragment-definition" }, { "include": "#graphql-type-interface" }, { "include": "#graphql-enum" }, @@ -20,7 +22,6 @@ { "include": "#graphql-union" }, { "include": "#graphql-schema" }, { "include": "#graphql-operation-def" }, - { "include": "#graphql-comment" }, { "include": "#literal-quasi-embedded" } ] }, @@ -45,6 +46,7 @@ }, "patterns": [ { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-selection-set" }, { "include": "#graphql-directive" }, { "include": "#graphql-skip-newlines" }, @@ -85,8 +87,9 @@ { "include": "#graphql-comma" } ] }, - { "include": "#graphql-directive" }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-directive" }, { "include": "#graphql-type-object" }, { "include": "#literal-quasi-embedded" } ] @@ -102,9 +105,9 @@ "1": { "name": "punctuation.operation.graphql"} }, "patterns": [ - { "include": "#graphql-object-type" }, - { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-object-type" }, { "include": "#graphql-type-definition" }, { "include": "#literal-quasi-embedded" } ] @@ -121,6 +124,7 @@ }, "patterns": [ { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-variable-definitions" }, { "include": "#graphql-type-object" }, { "include": "#graphql-colon"}, @@ -161,26 +165,44 @@ "1": { "name": "support.type.graphql" } } }, - { "include": "#graphql-colon" }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-colon" }, { "include": "#graphql-skip-newlines" } ] }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-skip-newlines" } ] }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-skip-newlines" } ] }, "graphql-comment": { "comment": "need to prefix comment space with a scope else Atom's reflow cmd doesn't work", - "name": "comment.line.graphql.js", - "match": "(\\s*)(#).*", - "captures": { - "1": { "name": "punctuation.whitespace.comment.leading.graphql" } - } + "name": "comment.line.graphql", + "match": "\\s*#.*" + }, + "graphql-description": { + "comment": "In new graphql spec 0.12.0, the description has to enclosed in two lines of triple quotes", + "name": "graphql.description", + "begin": "^\\s*(\"\"\")$", + "beginCaptures": { + "1": { "name": "comment.quoted.double.graphql.begin" } + }, + "end": "^\\s*(\"\"\")$", + "endCaptures": { + "1": { "name": "comment.quoted.double.graphql.end" } + }, + "patterns": [ + { + "name": "comment.line.graphql", + "match": "^\\s*.*$" + } + ] }, "graphql-variable-definitions": { "begin": "\\s*(\\()", @@ -190,6 +212,7 @@ }, "patterns": [ { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-variable-definition"}, { "include": "#literal-quasi-embedded" } ] @@ -207,6 +230,7 @@ }, "patterns": [ { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-colon" }, { "include": "#graphql-input-types"}, { "include": "#graphql-variable-assignment"}, @@ -233,8 +257,9 @@ "2": { "name": "keyword.operator.nulltype.graphql" } }, "patterns": [ - { "include": "#graphql-input-types" }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-input-types" }, { "include": "#graphql-comma" }, { "include": "#literal-quasi-embedded" } ] @@ -298,8 +323,9 @@ "1": { "name": "entity.name.function.directive.graphql" } }, "patterns": [ - { "include": "#graphql-arguments"}, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-arguments"}, { "include": "#literal-quasi-embedded" }, { "include": "#graphql-skip-newlines" } ] @@ -315,11 +341,12 @@ "1": { "name": "punctuation.operation.graphql"} }, "patterns": [ + { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-field" }, { "include": "#graphql-fragment-spread" }, { "include": "#graphql-inline-fragment" }, { "include": "#graphql-comma" }, - { "include": "#graphql-comment" }, { "include": "#native-interpolation" }, { "include": "#literal-quasi-embedded" } ] @@ -356,6 +383,7 @@ }, "patterns": [ { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-selection-set" }, { "include": "#graphql-directive" }, { "include": "#literal-quasi-embedded" }, @@ -373,6 +401,7 @@ }, "patterns": [ { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-selection-set" }, { "include": "#graphql-directive" }, { "include": "#graphql-skip-newlines" }, @@ -391,6 +420,7 @@ }, "patterns": [ { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "begin": "\\s*([_A-Za-z][_0-9A-Za-z]*)(?:\\s*(:))", "end": "(?=\\s*(?:(?:([_A-Za-z][_0-9A-Za-z]*)\\s*(:))|\\)))|\\s*(,)", @@ -402,8 +432,9 @@ "3": { "name": "punctuation.comma.graphql" } }, "patterns": [ - { "include": "#graphql-value" }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-value" }, { "include": "#graphql-skip-newlines" } ] }, @@ -485,6 +516,7 @@ { "include": "#graphql-object-type" }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-enum-value" }, { "include": "#literal-quasi-embedded" } ] @@ -497,6 +529,8 @@ }, "graphql-value":{ "patterns": [ + { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, { "include": "#graphql-variable-name" }, { "include": "#graphql-float-value" }, { "include": "#graphql-string-value" }, @@ -505,7 +539,6 @@ { "include": "#graphql-enum-value" }, { "include": "#graphql-list-value" }, { "include": "#graphql-object-value" }, - { "include": "#graphql-comment" }, { "include": "#literal-quasi-embedded" } ] }, @@ -572,8 +605,9 @@ "2": { "name": "support.type.graphql" } }, "patterns": [ - { "include": "#graphql-skip-newlines" }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-skip-newlines" }, { "include": "#literal-quasi-embedded" }, { "match": "\\s*(\\|)\\s*([_A-Za-z][_0-9A-Za-z]*)", @@ -584,8 +618,9 @@ } ] }, - { "include": "#graphql-skip-newlines" }, { "include": "#graphql-comment" }, + { "include": "#graphql-description" }, + { "include": "#graphql-skip-newlines" }, { "include": "#literal-quasi-embedded" } ] },