Add tsx provider, closes #330

This commit is contained in:
Adam Stankiewicz 2019-06-08 13:03:18 +02:00
parent 5023da62ec
commit 0217fb50fe
7 changed files with 222 additions and 7 deletions

View File

@ -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. > 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 **won't affect your startup time**, as scripts are loaded only on demand\*.
- It **installs and updates 120+ times faster** than the <!--Package Count-->137<!--/Package Count--> packages it consists of. - It **installs and updates 120+ times faster** than the <!--Package Count-->138<!--/Package Count--> packages it consists of.
- Solid syntax and indentation support (other features skipped). Only the best language packs. - Solid syntax and indentation support (other features skipped). Only the best language packs.
- All unnecessary files are ignored (like enormous documentation from php support). - All unnecessary files are ignored (like enormous documentation from php support).
- No support for esoteric languages, only most popular ones (modern too, like `slim`). - No support for esoteric languages, only most popular ones (modern too, like `slim`).
@ -169,6 +169,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [tomdoc](https://github.com/wellbredgrapefruit/tomdoc.vim) (syntax) - [tomdoc](https://github.com/wellbredgrapefruit/tomdoc.vim) (syntax)
- [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin) - [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin)
- [tptp](https://github.com/c-cube/vim-tptp) (syntax) - [tptp](https://github.com/c-cube/vim-tptp) (syntax)
- [tsx](https://github.com/ianks/vim-tsx) (syntax, indent, ftplugin)
- [twig](https://github.com/lumiliet/vim-twig) (syntax, indent, ftplugin) - [twig](https://github.com/lumiliet/vim-twig) (syntax, indent, ftplugin)
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin) - [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin)
- [vala](https://github.com/arrufat/vala.vim) (syntax, indent) - [vala](https://github.com/arrufat/vala.vim) (syntax, indent)

21
after/ftplugin/tsx.vim Normal file
View File

@ -0,0 +1,21 @@
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'tsx') != -1
finish
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim ftplugin file
"
" Language: TSX (JavaScript)
" Maintainer: Ian Ker-Seymer <i.kerseymer@gmail.com>
" Depends: leafgarland/typescript-vim
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" modified from html.vim
if exists("loaded_matchit")
let b:match_ignorecase = 0
let b:match_words = '(:),\[:\],{:},<:>,' .
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
endif
setlocal suffixesadd+=.tsx

95
after/indent/tsx.vim Normal file
View File

@ -0,0 +1,95 @@
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'tsx') != -1
finish
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim indent file
"
" Language: TSX (JavaScript)
" Maintainer: Ian Ker-Seymer <i.kerseymer@gmail.com>
" Depends: pangloss/vim-typescript
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Prologue; load in XML indentation.
if exists('b:did_indent')
let s:did_indent=b:did_indent
unlet b:did_indent
endif
exe 'runtime! indent/xml.vim'
if exists('s:did_indent')
let b:did_indent=s:did_indent
endif
setlocal indentexpr=GetTsxIndent()
" TS indentkeys
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
" XML indentkeys
setlocal indentkeys+=*<Return>,<>>,<<>,/
" Self-closing tag regex.
let s:sctag = '^\s*\/>\s*;\='
" Get all syntax types at the beginning of a given line.
fu! SynSOL(lnum)
return map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
endfu
" Get all syntax types at the end of a given line.
fu! SynEOL(lnum)
let lnum = prevnonblank(a:lnum)
let col = strlen(getline(lnum))
return map(synstack(lnum, col), 'synIDattr(v:val, "name")')
endfu
" Check if a syntax attribute is XMLish.
fu! SynAttrXMLish(synattr)
return a:synattr =~ "^xml" || a:synattr =~ "^tsx"
endfu
" Check if a synstack is XMLish (i.e., has an XMLish last attribute).
fu! SynXMLish(syns)
return SynAttrXMLish(get(a:syns, -1))
endfu
" Check if a synstack has any XMLish attribute.
fu! SynXMLishAny(syns)
for synattr in a:syns
if SynAttrXMLish(synattr)
return 1
endif
endfor
return 0
endfu
" Check if a synstack denotes the end of a TSX block.
fu! SynTSXBlockEnd(syns)
return get(a:syns, -1) == 'tsBraces' && SynAttrXMLish(get(a:syns, -2))
endfu
" Cleverly mix TS and XML indentation.
fu! GetTsxIndent()
let cursyn = SynSOL(v:lnum)
let prevsyn = SynEOL(v:lnum - 1)
" Use XML indenting if the syntax at the end of the previous line was either
" TSX or was the closing brace of a tsBlock whose parent syntax was TSX.
if (SynXMLish(prevsyn) || SynTSXBlockEnd(prevsyn)) && SynXMLishAny(cursyn)
let ind = XmlIndentGet(v:lnum, 0)
" Align '/>' with '<' for multiline self-closing tags.
if getline(v:lnum) =~? s:sctag
let ind = ind - &sw
endif
" Then correct the indentation of any TSX following '/>'.
if getline(v:lnum - 1) =~? s:sctag
let ind = ind + &sw
endif
else
let ind = GetTypescriptIndent()
endif
return ind
endfu

87
after/syntax/tsx.vim Normal file
View File

@ -0,0 +1,87 @@
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'tsx') != -1
finish
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim syntax file
"
" Language: TSX (JavaScript)
" Maintainer: Ian Ker-Seymer <i.kerseymer@gmail.com>
" Depends: leafgarland/typescript-vim
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if exists('b:current_syntax')
let s:current_syntax=b:current_syntax
unlet b:current_syntax
endif
syn include @XMLSyntax syntax/xml.vim
if exists('s:current_syntax')
let b:current_syntax=s:current_syntax
endif
syn region embeddedTs
\ matchgroup=NONE
\ start=+{+
\ end=+}+
\ contains=@Spell,@typescriptAll,xmlEntity,tsxRegion
\ contained
" Add embeddedTs to everything where xmlString is used to allow for
" both string highlighting and @typescriptAll highlighting
syn region xmlTag
\ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+
\ matchgroup=xmlTag end=+>+
\ contained
\ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook,embeddedTs
syn region xmlProcessing
\ matchgroup=xmlProcessingDelim
\ start="<?"
\ end="?>"
\ contains=xmlAttrib,xmlEqual,xmlString,embeddedTs
if exists('g:xml_syntax_folding')
" DTD -- we use dtd.vim here
syn region xmlDocType matchgroup=xmlDocTypeDecl
\ start="<!DOCTYPE"he=s+2,rs=s+2
\ end=">"
\ fold
\ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString,embeddedTs
else
syn region xmlDocType matchgroup=xmlDocTypeDecl
\ start="<!DOCTYPE"he=s+2,rs=s+2
\ end=">"
\ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString,embeddedTs
endif
if exists('g:xml_syntax_folding')
syn region xmlTag
\ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+
\ matchgroup=xmlTag end=+>+
\ contained
\ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook,embeddedTs
else
syn region xmlTag
\ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+
\ matchgroup=xmlTag end=+>+
\ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook,embeddedTs
endif
syn region tsxRegion
\ contains=@Spell,@XMLSyntax,tsxRegion,@typescriptAll
\ start=+\%(<\|\w\)\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
\ skip=+<!--\_.\{-}-->+
\ end=+</\z1\_\s\{-}>+
\ end=+/>+
\ keepend
\ extend
hi def link embeddedTs NONE
syn cluster @typescriptAll add=tsxRegion

1
build
View File

@ -277,6 +277,7 @@ PACKS="
tomdoc:wellbredgrapefruit/tomdoc.vim tomdoc:wellbredgrapefruit/tomdoc.vim
toml:cespare/vim-toml toml:cespare/vim-toml
tptp:c-cube/vim-tptp tptp:c-cube/vim-tptp
tsx:ianks/vim-tsx
twig:lumiliet/vim-twig twig:lumiliet/vim-twig
typescript:leafgarland/typescript-vim typescript:leafgarland/typescript-vim
vala:arrufat/vala.vim vala:arrufat/vala.vim

View File

@ -79,9 +79,6 @@ augroup filetypedetect
"jinja "jinja
autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja
"tsx
autocmd BufNewFile,BufRead *.tsx setfiletype typescript.jsx
augroup END augroup END
" Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954

View File

@ -79,9 +79,6 @@ augroup filetypedetect
"jinja "jinja
autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja
"tsx
autocmd BufNewFile,BufRead *.tsx setfiletype typescript.jsx
augroup END augroup END
" Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954
@ -1374,6 +1371,22 @@ au BufRead,BufNewFile *.ax set syntax=tptp
augroup end augroup end
endif endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'tsx') == -1
augroup filetypedetect
" tsx, from typescript.vim in ianks/vim-tsx
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim ftdetect file
"
" Language: TSX (JavaScript)
" Maintainer: Ian Ker-Seymer <i.kerseymer@gmail.com>
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufNewFile,BufRead *.tsx let b:tsx_ext_found = 1
autocmd BufNewFile,BufRead *.tsx set filetype=typescript.tsx
augroup end
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'twig') == -1 if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'twig') == -1
augroup filetypedetect augroup filetypedetect
" twig, from twig.vim in lumiliet/vim-twig " twig, from twig.vim in lumiliet/vim-twig