diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2019-09-04 16:29:56 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2019-09-04 16:29:56 +0200 |
commit | 556c56d185fcc7d5cc6d51ea9a6453bcd4f7116c (patch) | |
tree | f97d9f0cdf9df718aaf1a04eed16819a84a5bab2 | |
parent | fe84062992e12dea8e090e647afa6b314e891f73 (diff) | |
download | vim-polyglot-556c56d185fcc7d5cc6d51ea9a6453bcd4f7116c.tar.gz vim-polyglot-556c56d185fcc7d5cc6d51ea9a6453bcd4f7116c.zip |
Add graphql support, closes #298
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | after/autoload/styledcomplete.vim | 42 | ||||
-rw-r--r-- | after/syntax/javascript/graphql.vim | 27 | ||||
-rw-r--r-- | after/syntax/typescript/graphql.vim | 26 | ||||
-rw-r--r-- | autoload/graphql.vim | 16 | ||||
-rwxr-xr-x | build | 1 | ||||
-rw-r--r-- | ftdetect/polyglot.vim | 8 | ||||
-rw-r--r-- | ftplugin/graphql.vim | 22 | ||||
-rw-r--r-- | indent/graphql.vim | 81 | ||||
-rw-r--r-- | syntax/graphql.vim | 68 |
10 files changed, 293 insertions, 1 deletions
@@ -10,7 +10,7 @@ A collection of language packs for Vim. > One to rule them all, one to find them, one to bring them all and in the darkness bind them. - It **won't affect your startup time**, as scripts are loaded only on demand\*. -- It **installs and updates 120+ times faster** than the <!--Package Count-->146<!--/Package Count--> packages it consists of. +- It **installs and updates 120+ times faster** than the <!--Package Count-->147<!--/Package Count--> packages it consists of. - Solid syntax and indentation support (other features skipped). Only the best language packs. - All unnecessary files are ignored (like enormous documentation from php support). - No support for esoteric languages, only most popular ones (modern too, like `slim`). @@ -86,6 +86,7 @@ If you need full functionality of any plugin, please use it directly with your p - [gnuplot](https://github.com/vim-scripts/gnuplot-syntax-highlighting) (syntax) - [go](https://github.com/fatih/vim-go) (syntax, compiler, indent) - [gradle](https://github.com/tfnico/vim-gradle) (compiler) +- [graphql](https://github.com/jparise/vim-graphql) (syntax, indent, autoload, ftplugin, after) - [groovy-indent](https://github.com/vim-scripts/groovyindent-unix) (indent) - [groovy](https://github.com/vim-scripts/groovy.vim) (syntax) - [haml](https://github.com/sheerun/vim-haml) (syntax, indent, compiler, ftplugin) diff --git a/after/autoload/styledcomplete.vim b/after/autoload/styledcomplete.vim index efa992c4..d1a8859d 100644 --- a/after/autoload/styledcomplete.vim +++ b/after/autoload/styledcomplete.vim @@ -19,3 +19,45 @@ fun! styledcomplete#CompleteSC(findstart, base) return s:funcref(a:findstart, a:base) endif endfun +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'styled-components') != -1 + finish +endif + +" Vim completion script +" Language: styled-components (js/ts) +" Maintainer: Karl Fleischmann <fleischmann.karl@gmail.com> +" URL: https://github.com/styled-components/vim-styled-components + +fun! styledcomplete#CompleteSC(findstart, base) + if IsStyledDefinition(line('.')) + return csscomplete#CompleteCSS(a:findstart, a:base) + endif + + " Only trigger original omnifunc if it was set in the first place + if exists('b:prevofu') + " create a funcref to call with the previous omnicomplete function + let s:funcref = function(b:prevofu) + return s:funcref(a:findstart, a:base) + endif +endfun +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'styled-components') != -1 + finish +endif + +" Vim completion script +" Language: styled-components (js/ts) +" Maintainer: Karl Fleischmann <fleischmann.karl@gmail.com> +" URL: https://github.com/styled-components/vim-styled-components + +fun! styledcomplete#CompleteSC(findstart, base) + if IsStyledDefinition(line('.')) + return csscomplete#CompleteCSS(a:findstart, a:base) + endif + + " Only trigger original omnifunc if it was set in the first place + if exists('b:prevofu') + " create a funcref to call with the previous omnicomplete function + let s:funcref = function(b:prevofu) + return s:funcref(a:findstart, a:base) + endif +endfun diff --git a/after/syntax/javascript/graphql.vim b/after/syntax/javascript/graphql.vim new file mode 100644 index 00000000..edc8eea1 --- /dev/null +++ b/after/syntax/javascript/graphql.vim @@ -0,0 +1,27 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'graphql') != -1 + finish +endif + +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 + +let s:tags = '\%(' . join(graphql#javascript_tags(), '\|') . '\)' + +exec 'syntax region graphqlTemplateString start=+' . s:tags . '\@20<=`+ skip=+\\`+ end=+`+ contains=@GraphQLSyntax,jsTemplateExpression,jsSpecial extend' +exec 'syntax match graphqlTaggedTemplate +' . s:tags . '\ze`+ nextgroup=graphqlTemplateString' + +" Support expression interpolation ((${...})) inside template strings. +syntax region graphqlTemplateExpression start=+${+ end=+}+ contained contains=jsTemplateExpression containedin=graphqlFold keepend + +hi def link graphqlTemplateString jsTemplateString +hi def link graphqlTaggedTemplate jsTaggedTemplate +hi def link graphqlTemplateExpression jsTemplateExpression + +syn cluster jsExpression add=graphqlTaggedTemplate +syn cluster graphqlTaggedTemplate add=graphqlTemplateString diff --git a/after/syntax/typescript/graphql.vim b/after/syntax/typescript/graphql.vim new file mode 100644 index 00000000..fc070daa --- /dev/null +++ b/after/syntax/typescript/graphql.vim @@ -0,0 +1,26 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'graphql') != -1 + finish +endif + +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 + +let s:tags = '\%(' . join(graphql#javascript_tags(), '\|') . '\)' + +exec 'syntax region graphqlTemplateString start=+' . s:tags . '\@20<=`+ skip=+\\`+ end=+`+ contains=@GraphQLSyntax,typescriptTemplateSubstitution extend' +exec 'syntax match graphqlTaggedTemplate +' . s:tags . '\ze`+ nextgroup=graphqlTemplateString' + +" Support expression interpolation ((${...})) inside template strings. +syntax region graphqlTemplateExpression start=+${+ end=+}+ contained contains=typescriptTemplateSubstitution containedin=graphqlFold keepend + +hi def link graphqlTemplateString typescriptTemplate +hi def link graphqlTemplateExpression typescriptTemplateSubstitution + +syn cluster typescriptExpression add=graphqlTaggedTemplate +syn cluster graphqlTaggedTemplate add=graphqlTemplateString diff --git a/autoload/graphql.vim b/autoload/graphql.vim new file mode 100644 index 00000000..cce43556 --- /dev/null +++ b/autoload/graphql.vim @@ -0,0 +1,16 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'graphql') != -1 + finish +endif + +" Vim plugin +" Language: GraphQL +" Maintainer: Jon Parise <jon@indelible.org> + +if exists('g:autoloaded_graphql') + finish +endif +let g:autoloaded_graphql = 1 + +function! graphql#javascript_tags() abort + return get(g:, 'graphql_javascript_tags', ['gql', 'graphql', 'Relay.QL']) +endfunction @@ -195,6 +195,7 @@ PACKS=" gmpl:maelvalais/gmpl.vim gnuplot:vim-scripts/gnuplot-syntax-highlighting go:fatih/vim-go:_BASIC + graphql:jparise/vim-graphql:_ALL gradle:tfnico/vim-gradle groovy:vim-scripts/groovy.vim groovy-indent:vim-scripts/groovyindent-unix diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index af4d6941..7e3dc45f 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -505,6 +505,14 @@ unlet s:cpo_save augroup end endif +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 + augroup filetypedetect + " graphql, from graphql.vim in jparise/vim-graphql:_ALL +" vint: -ProhibitAutocmdWithNoGroup +au BufRead,BufNewFile *.graphql,*.graphqls,*.gql setfiletype graphql + augroup end +endif + if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'gradle') == -1 augroup filetypedetect " gradle, from gradle.vim in tfnico/vim-gradle diff --git a/ftplugin/graphql.vim b/ftplugin/graphql.vim new file mode 100644 index 00000000..7734acee --- /dev/null +++ b/ftplugin/graphql.vim @@ -0,0 +1,22 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'graphql') != -1 + finish +endif + +" 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+=$,@-@ +setlocal softtabstop=2 +setlocal shiftwidth=2 +setlocal expandtab + +let b:undo_ftplugin = 'setlocal com< cms< fo< isk< sts< sw< et<' diff --git a/indent/graphql.vim b/indent/graphql.vim new file mode 100644 index 00000000..1bf93abb --- /dev/null +++ b/indent/graphql.vim @@ -0,0 +1,81 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'graphql') != -1 + finish +endif + +" 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 + +" 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 diff --git a/syntax/graphql.vim b/syntax/graphql.vim new file mode 100644 index 00000000..06223576 --- /dev/null +++ b/syntax/graphql.vim @@ -0,0 +1,68 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'graphql') != -1 + finish +endif + +" 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="}" transparent fold contains=ALLBUT,graphqlStructure +syn region graphqlList matchgroup=graphqlBraces start="\[" end="]" 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' |