From 13e670b1a8422f9aa92d4da3e6a9ceea175b8dc2 Mon Sep 17 00:00:00 2001 From: Paul Rosania Date: Wed, 19 Oct 2016 21:45:11 -0700 Subject: [PATCH] Support ES6 tagged template literals This patch adds support for GraphQL syntax in ES6 tagged template literals. (As used by `graphql-tag`, for example.) By default, GraphQL syntax is highlighted in template literals tagged with `gql` or `graphql`. This can be configured via the `g:graphql_tag_names` array. --- after/syntax/javascript/graphql.vim | 18 ++++++++++++++++++ plugin/graphql.vim | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 after/syntax/javascript/graphql.vim create mode 100644 plugin/graphql.vim diff --git a/after/syntax/javascript/graphql.vim b/after/syntax/javascript/graphql.vim new file mode 100644 index 0000000..e837737 --- /dev/null +++ b/after/syntax/javascript/graphql.vim @@ -0,0 +1,18 @@ +" Prologue; load in GraphQL syntax. +if exists('b:current_syntax') + let s:current_syntax=b:current_syntax + unlet b:current_syntax +endif +syn include @GraphQLSyntax syntax/graphql.vim +if exists('s:current_syntax') + let b:current_syntax=s:current_syntax +endif + +syntax region graphqlTemplateString start=+`+ skip=+\\\(`\|$\)+ end=+`+ contains=@GraphQLSyntax,jsTemplateVar,jsSpecial extend +exec 'syntax match graphqlTaggedTemplate +\%(' . join(g:graphql_tag_names, '\|') . '\)\%(`\)\@=+ nextgroup=graphqlTemplateString' + +hi def link graphqlTemplateString jsTemplateString +hi def link graphqlTaggedTemplate jsTaggedTemplate + +syn cluster jsExpression add=graphqlTaggedTemplate +syn cluster graphqlTaggedTemplate add=graphqlTemplateString diff --git a/plugin/graphql.vim b/plugin/graphql.vim new file mode 100644 index 0000000..419ef0e --- /dev/null +++ b/plugin/graphql.vim @@ -0,0 +1,3 @@ +if (!exists('g:graphql_tag_names')) + let g:graphql_tag_names = ['gql', 'graphql'] +endif