Skip to content

Commit 13e670b

Browse files
committed
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.
1 parent 88abf6e commit 13e670b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
" Prologue; load in GraphQL syntax.
2+
if exists('b:current_syntax')
3+
let s:current_syntax=b:current_syntax
4+
unlet b:current_syntax
5+
endif
6+
syn include @GraphQLSyntax syntax/graphql.vim
7+
if exists('s:current_syntax')
8+
let b:current_syntax=s:current_syntax
9+
endif
10+
11+
syntax region graphqlTemplateString start=+`+ skip=+\\\(`\|$\)+ end=+`+ contains=@GraphQLSyntax,jsTemplateVar,jsSpecial extend
12+
exec 'syntax match graphqlTaggedTemplate +\%(' . join(g:graphql_tag_names, '\|') . '\)\%(`\)\@=+ nextgroup=graphqlTemplateString'
13+
14+
hi def link graphqlTemplateString jsTemplateString
15+
hi def link graphqlTaggedTemplate jsTaggedTemplate
16+
17+
syn cluster jsExpression add=graphqlTaggedTemplate
18+
syn cluster graphqlTaggedTemplate add=graphqlTemplateString

plugin/graphql.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (!exists('g:graphql_tag_names'))
2+
let g:graphql_tag_names = ['gql', 'graphql']
3+
endif

0 commit comments

Comments
 (0)