diff options
Diffstat (limited to 'after/syntax/tsx.vim')
-rw-r--r-- | after/syntax/tsx.vim | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/after/syntax/tsx.vim b/after/syntax/tsx.vim index 863da121..36854168 100644 --- a/after/syntax/tsx.vim +++ b/after/syntax/tsx.vim @@ -1,28 +1,63 @@ -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 +if !exists('g:polyglot_disabled') || !(index(g:polyglot_disabled, 'typescript') != -1 || index(g:polyglot_disabled, 'typescript') != -1 || index(g:polyglot_disabled, 'jsx') != -1) + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Vim syntax file +" +" Language: javascript.jsx +" Maintainer: MaxMellon <maxmellon1994@gmail.com> +" Depends: leafgarland/typescript-vim +" +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +if get(g:, 'vim_jsx_pretty_disable_tsx', 0) + finish +endif + +let s:jsx_cpo = &cpo +set cpo&vim + +syntax case match -" GraphQL Support 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 +" refine the typescript line comment +syntax region typescriptLineComment start=+//+ end=/$/ contains=@Spell,typescriptCommentTodo,typescriptRef extend keepend + +for syntax_name in ['tsxRegion', 'tsxFragment'] + if hlexists(syntax_name) + exe 'syntax clear ' . syntax_name + endif +endfor + +if !hlexists('typescriptTypeCast') + " add a typescriptBlock group for typescript + syntax region typescriptBlock + \ matchgroup=typescriptBraces + \ start="{" + \ end="}" + \ contained + \ extend + \ contains=@typescriptExpression,typescriptBlock + \ fold + hi def link typescriptTypeBrackets typescriptOpSymbols +endif -hi def link graphqlTemplateString typescriptTemplate -hi def link graphqlTemplateExpression typescriptTemplateSubstitution +runtime syntax/jsx_pretty.vim +syntax cluster typescriptExpression add=jsxRegion,typescriptParens +" Fix type casting ambiguity with JSX syntax +syntax match typescriptTypeBrackets +[<>]+ contained +syntax match typescriptTypeCast +<\([_$A-Za-z0-9]\+\)>\%(\s*\%([_$A-Za-z0-9]\+\s*;\?\|(\)\%(\_[^<]*</\1>\)\@!\)\@=+ contains=typescriptTypeBrackets,@typescriptType,typescriptType nextgroup=@typescriptExpression -syn cluster typescriptExpression add=graphqlTaggedTemplate -syn cluster graphqlTaggedTemplate add=graphqlTemplateString +let b:current_syntax = 'typescript.tsx' +let &cpo = s:jsx_cpo +unlet s:jsx_cpo endif |