Skip to content

Support for JavaScript tagged template literals #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test/vim-javascript/
test/vader.vim/
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

all: test

test: test/vader.vim
test: test/vader.vim test/vim-javascript
cd test && vim -Nu vimrc -c 'Vader! *' > /dev/null

test/vader.vim:
git clone --depth 1 https://github.com/junegunn/vader.vim test/vader.vim
git clone --depth 1 https://github.com/junegunn/vader.vim.git test/vader.vim

test/vim-javascript:
git clone --depth 1 https://github.com/pangloss/vim-javascript.git test/vim-javascript
17 changes: 17 additions & 0 deletions after/syntax/javascript/graphql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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,jsTemplateExpression,jsSpecial extend
exec 'syntax match graphqlTaggedTemplate +\%(' . join(g:graphql_javascript_tags, '\|') . '\)\%(`\)\@=+ 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_javascript_tags'))
let g:graphql_javascript_tags = ['gql', 'graphql', 'Relay.QL']
endif
17 changes: 17 additions & 0 deletions test/javascript.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Before:
source ../after/syntax/javascript/graphql.vim

Given javascript (Query):
const query = gql`
{
user(id: 5) {
firstName
lastName
}
}
`

Execute (Syntax assertions):
AssertEqual 'graphqlTaggedTemplate', SyntaxOf('gql')
AssertEqual 'graphqlTemplateString', SyntaxOf('`')
AssertEqual 'graphqlIdentifier', SyntaxOf('user')
3 changes: 2 additions & 1 deletion test/vimrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
filetype off
set rtp+=vader.vim
set rtp+=vader.vim/
set rtp+=vim-javascript/
set rtp+=../
filetype plugin indent on
syntax enable