summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--after/syntax/javascript/graphql.vim21
-rw-r--r--after/syntax/typescript/graphql.vim20
-rwxr-xr-xbuild1
-rw-r--r--ftdetect/polyglot.vim7
-rw-r--r--ftplugin/graphql.vim17
-rw-r--r--indent/graphql.vim81
-rw-r--r--syntax/graphql.vim68
8 files changed, 216 insertions, 0 deletions
diff --git a/README.md b/README.md
index 586c7d34..bcb42585 100644
--- a/README.md
+++ b/README.md
@@ -75,6 +75,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [gmpl](https://github.com/maelvalais/gmpl.vim) (syntax)
- [gnuplot](https://github.com/vim-scripts/gnuplot-syntax-highlighting) (syntax)
- [go](https://github.com/fatih/vim-go) (syntax, compiler, indent)
+- [graphql](https://github.com/jparise/vim-graphql) (syntax, indent, ftplugin)
- [groovy](https://github.com/vim-scripts/groovy.vim) (syntax)
- [haml](https://github.com/sheerun/vim-haml) (syntax, indent, compiler, ftplugin)
- [handlebars](https://github.com/mustache/vim-mustache-handlebars) (syntax, indent, ftplugin)
diff --git a/after/syntax/javascript/graphql.vim b/after/syntax/javascript/graphql.vim
new file mode 100644
index 00000000..58c1de08
--- /dev/null
+++ b/after/syntax/javascript/graphql.vim
@@ -0,0 +1,21 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
+
+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
+
+endif
diff --git a/after/syntax/typescript/graphql.vim b/after/syntax/typescript/graphql.vim
new file mode 100644
index 00000000..53999699
--- /dev/null
+++ b/after/syntax/typescript/graphql.vim
@@ -0,0 +1,20 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
+
+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,typescriptTemplateTag extend
+exec 'syntax match graphqlTaggedTemplate +\%(' . join(g:graphql_javascript_tags, '\|') . '\)\%(`\)\@=+ nextgroup=graphqlTemplateString'
+
+hi def link graphqlTemplateString typescriptTemplate
+
+syn cluster typescriptExpression add=graphqlTaggedTemplate
+syn cluster graphqlTaggedTemplate add=graphqlTemplateString
+
+endif
diff --git a/build b/build
index ebabe288..0cb56f28 100755
--- a/build
+++ b/build
@@ -175,6 +175,7 @@ PACKS="
glsl:tikhomirov/vim-glsl
gnuplot:vim-scripts/gnuplot-syntax-highlighting
go:fatih/vim-go:_BASIC
+ graphql:jparise/vim-graphql
groovy:vim-scripts/groovy.vim
haml:sheerun/vim-haml
handlebars:mustache/vim-mustache-handlebars
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 0619d65f..bb28828c 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -362,6 +362,13 @@ au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl
augroup end
endif
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
+ augroup filetypedetect
+ " graphql, from graphql.vim in jparise/vim-graphql
+au BufRead,BufNewFile *.graphql,*.graphqls,*.gql setfiletype graphql
+ augroup end
+endif
+
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haml') == -1
augroup filetypedetect
" haml, from haml.vim in sheerun/vim-haml
diff --git a/ftplugin/graphql.vim b/ftplugin/graphql.vim
new file mode 100644
index 00000000..42d96e6c
--- /dev/null
+++ b/ftplugin/graphql.vim
@@ -0,0 +1,17 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
+
+" Vim filetype plugin
+" Language: GraphQL
+" Maintainer: Jon Parise <jon@indelible.org>
+
+if (exists('b:did_ftplugin'))
+ finish
+endif
+let b:did_ftplugin = 1
+
+setlocal comments=:#
+setlocal commentstring=#\ %s
+setlocal formatoptions-=t
+setlocal iskeyword+=$,@-@
+
+endif
diff --git a/indent/graphql.vim b/indent/graphql.vim
new file mode 100644
index 00000000..ed9cfaa2
--- /dev/null
+++ b/indent/graphql.vim
@@ -0,0 +1,81 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
+
+" Vim indent file
+" Language: GraphQL
+" Maintainer: Jon Parise <jon@indelible.org>
+
+if exists('b:did_indent')
+ finish
+endif
+let b:did_indent = 1
+
+setlocal autoindent
+setlocal nocindent
+setlocal nolisp
+setlocal nosmartindent
+
+setlocal indentexpr=GetGraphQLIndent()
+setlocal indentkeys=0{,0},0),0[,0],0#,!^F,o,O,e
+
+" If our indentation function already exists, we have nothing more to do.
+if exists('*GetGraphQLIndent')
+ finish
+endif
+
+let s:cpo_save = &cpoptions
+set cpoptions&vim
+
+" Check if the character at lnum:col is inside a string.
+function s:InString(lnum, col)
+ return synIDattr(synID(a:lnum, a:col, 1), 'name') is# 'graphqlString'
+endfunction
+
+function GetGraphQLIndent()
+ " If this is the first non-blank line, we have nothing more to do because
+ " all of our indentation rules are based on matching against earlier lines.
+ let l:prevlnum = prevnonblank(v:lnum - 1)
+ if l:prevlnum == 0
+ return 0
+ endif
+
+ let l:line = getline(v:lnum)
+
+ " If this line contains just a closing bracket, find its matching opening
+ " bracket and indent the closing backet to match.
+ let l:col = matchend(l:line, '^\s*[]})]')
+ if l:col > 0 && !s:InString(v:lnum, l:col)
+ let l:bracket = l:line[l:col - 1]
+ call cursor(v:lnum, l:col)
+
+ if l:bracket is# '}'
+ let l:matched = searchpair('{', '', '}', 'bW')
+ elseif l:bracket is# ']'
+ let l:matched = searchpair('\[', '', '\]', 'bW')
+ elseif l:bracket is# ')'
+ let l:matched = searchpair('(', '', ')', 'bW')
+ else
+ let l:matched = -1
+ endif
+
+ return l:matched > 0 ? indent(l:matched) : virtcol('.') - 1
+ endif
+
+ " If we're inside of a multiline string, continue with the same indentation.
+ if s:InString(v:lnum, matchend(l:line, '^\s*') + 1)
+ return indent(v:lnum)
+ endif
+
+ " If the previous line contained an opening bracket, and we are still in it,
+ " add indent depending on the bracket type.
+ if getline(l:prevlnum) =~# '[[{(]\s*$'
+ return indent(l:prevlnum) + shiftwidth()
+ endif
+
+ " Default to the existing indentation level.
+ return indent(l:prevlnum)
+endfunction
+
+let &cpoptions = s:cpo_save
+unlet s:cpo_save
+
+endif
diff --git a/syntax/graphql.vim b/syntax/graphql.vim
new file mode 100644
index 00000000..c498afa4
--- /dev/null
+++ b/syntax/graphql.vim
@@ -0,0 +1,68 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
+
+" Vim syntax file
+" Language: GraphQL
+" Maintainer: Jon Parise <jon@indelible.org>
+
+if exists('b:current_syntax')
+ finish
+endif
+
+syn match graphqlComment "#.*$" contains=@Spell
+
+syn match graphqlOperator "=" display
+syn match graphqlOperator "!" display
+syn match graphqlOperator "|" display
+syn match graphqlOperator "\M..." display
+
+syn keyword graphqlBoolean true false
+syn keyword graphqlNull null
+syn match graphqlNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" display
+syn region graphqlString start=+"+ skip=+\\\\\|\\"+ end=+"\|$+
+syn region graphqlString start=+"""+ end=+"""+
+
+syn keyword graphqlKeyword on nextgroup=graphqlType skipwhite
+
+syn keyword graphqlStructure enum scalar type union nextgroup=graphqlType skipwhite
+syn keyword graphqlStructure input interface subscription nextgroup=graphqlType skipwhite
+syn keyword graphqlStructure implements nextgroup=graphqlType skipwhite
+syn keyword graphqlStructure query mutation fragment nextgroup=graphqlName skipwhite
+syn keyword graphqlStructure directive nextgroup=graphqlDirective skipwhite
+syn keyword graphqlStructure extend nextgroup=graphqlStructure skipwhite
+syn keyword graphqlStructure schema nextgroup=graphqlFold skipwhite
+
+syn match graphqlDirective "\<@\h\w*\>" display
+syn match graphqlVariable "\<\$\h\w*\>" display
+syn match graphqlName "\<\h\w*\>" display
+syn match graphqlType "\<_*\u\w*\>" display
+syn match graphqlConstant "\<[A-Z_]\+\>" display
+
+syn keyword graphqlMetaFields __schema __type __typename
+
+syn region graphqlFold matchgroup=graphqlBraces start="{" end=/}\(\_s\+\ze\("\|{\)\)\@!/ transparent fold contains=ALLBUT,graphqlStructure
+syn region graphqlList matchgroup=graphqlBraces start="\[" end=/]\(\_s\+\ze"\)\@!/ transparent contains=ALLBUT,graphqlDirective,graphqlStructure
+
+hi def link graphqlComment Comment
+hi def link graphqlOperator Operator
+
+hi def link graphqlBraces Delimiter
+
+hi def link graphqlBoolean Boolean
+hi def link graphqlNull Keyword
+hi def link graphqlNumber Number
+hi def link graphqlString String
+
+hi def link graphqlConstant Constant
+hi def link graphqlDirective PreProc
+hi def link graphqlName Identifier
+hi def link graphqlMetaFields Special
+hi def link graphqlKeyword Keyword
+hi def link graphqlStructure Structure
+hi def link graphqlType Type
+hi def link graphqlVariable Identifier
+
+syn sync minlines=500
+
+let b:current_syntax = 'graphql'
+
+endif