Skip to content

Commit

Permalink
Support ES6 tagged template literals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tessro committed Oct 20, 2016
1 parent 88abf6e commit 13e670b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions after/syntax/javascript/graphql.vim
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions plugin/graphql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (!exists('g:graphql_tag_names'))
let g:graphql_tag_names = ['gql', 'graphql']
endif

0 comments on commit 13e670b

Please sign in to comment.