This commit is contained in:
Adam Stankiewicz
2020-10-04 23:25:48 +02:00
parent 32b097f67e
commit cbc4600333
2 changed files with 16 additions and 18 deletions

View File

@@ -23,25 +23,24 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
" Language: GraphQL " Language: GraphQL
" Maintainer: Jon Parise <jon@indelible.org> " Maintainer: Jon Parise <jon@indelible.org>
runtime! indent/graphql.vim if exists('*GetJavascriptGraphQLIndent') && !empty(&indentexpr)
" Don't redefine our function and also require the standard Javascript indent
" function to exist.
if exists('*GetJavascriptGraphQLIndent') || !exists('*GetJavascriptIndent')
finish finish
endif endif
runtime! indent/graphql.vim
" Set the indentexpr with our own version that will call GetGraphQLIndent when " Set the indentexpr with our own version that will call GetGraphQLIndent when
" we're inside of a GraphQL string and otherwise defer to GetJavascriptIndent. " we're inside of a GraphQL string and otherwise defer to the base function.
let b:indentexpr_base = &indentexpr
setlocal indentexpr=GetJavascriptGraphQLIndent() setlocal indentexpr=GetJavascriptGraphQLIndent()
function GetJavascriptGraphQLIndent() function GetJavascriptGraphQLIndent()
let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val,'name')") let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val, 'name')")
if !empty(l:stack) && l:stack[0] ==# 'graphqlTemplateString' if get(l:stack, 0) ==# 'graphqlTemplateString'
return GetGraphQLIndent() return GetGraphQLIndent()
endif endif
return GetJavascriptIndent() return eval(b:indentexpr_base)
endfunction endfunction
endif endif

View File

@@ -23,25 +23,24 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
" Language: GraphQL " Language: GraphQL
" Maintainer: Jon Parise <jon@indelible.org> " Maintainer: Jon Parise <jon@indelible.org>
runtime! indent/graphql.vim if exists('*GetTypescriptGraphQLIndent') && !empty(&indentexpr)
" Don't redefine our function and also require the standard Typescript indent
" function to exist.
if exists('*GetTypescriptGraphQLIndent') || !exists('*GetTypescriptIndent')
finish finish
endif endif
runtime! indent/graphql.vim
" Set the indentexpr with our own version that will call GetGraphQLIndent when " Set the indentexpr with our own version that will call GetGraphQLIndent when
" we're inside of a GraphQL string and otherwise defer to GetTypescriptIndent. " we're inside of a GraphQL string and otherwise defer to the base function.
let b:indentexpr_base = &indentexpr
setlocal indentexpr=GetTypescriptGraphQLIndent() setlocal indentexpr=GetTypescriptGraphQLIndent()
function GetTypescriptGraphQLIndent() function GetTypescriptGraphQLIndent()
let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val,'name')") let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val, 'name')")
if !empty(l:stack) && l:stack[0] ==# 'graphqlTemplateString' if get(l:stack, 0) ==# 'graphqlTemplateString'
return GetGraphQLIndent() return GetGraphQLIndent()
endif endif
return GetTypescriptIndent() return eval(b:indentexpr_base)
endfunction endfunction
endif endif