Merge pull request #301 from timfeirg:feature/graphql
This commit is contained in:
parent
dc8b2f45de
commit
e2404449e4
@ -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)
|
||||
|
21
after/syntax/javascript/graphql.vim
Normal file
21
after/syntax/javascript/graphql.vim
Normal file
@ -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
|
20
after/syntax/typescript/graphql.vim
Normal file
20
after/syntax/typescript/graphql.vim
Normal file
@ -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
|
1
build
1
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
|
||||
|
@ -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
|
||||
|
17
ftplugin/graphql.vim
Normal file
17
ftplugin/graphql.vim
Normal file
@ -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
|
81
indent/graphql.vim
Normal file
81
indent/graphql.vim
Normal file
@ -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
|
68
syntax/graphql.vim
Normal file
68
syntax/graphql.vim
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user