diff --git a/README.md b/README.md index 2cf9255..07c3182 100644 --- a/README.md +++ b/README.md @@ -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 137 packages it consists of. +- It **installs and updates 120+ times faster** than the 138 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`). @@ -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) - [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin) - [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) - [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin) - [vala](https://github.com/arrufat/vala.vim) (syntax, indent) diff --git a/after/ftplugin/tsx.vim b/after/ftplugin/tsx.vim new file mode 100644 index 0000000..62112bb --- /dev/null +++ b/after/ftplugin/tsx.vim @@ -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 +" 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 diff --git a/after/indent/tsx.vim b/after/indent/tsx.vim new file mode 100644 index 0000000..a74c7be --- /dev/null +++ b/after/indent/tsx.vim @@ -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 +" 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+=*,<>>,<<>,/ + +" 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 diff --git a/after/syntax/tsx.vim b/after/syntax/tsx.vim new file mode 100644 index 0000000..05bfc9e --- /dev/null +++ b/after/syntax/tsx.vim @@ -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 +" 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="" + \ contains=xmlAttrib,xmlEqual,xmlString,embeddedTs + + +if exists('g:xml_syntax_folding') + " DTD -- we use dtd.vim here + syn region xmlDocType matchgroup=xmlDocTypeDecl + \ start="" + \ fold + \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString,embeddedTs +else + syn region xmlDocType matchgroup=xmlDocTypeDecl + \ start="" + \ 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\)\@+ + \ end=++ + \ end=+/>+ + \ keepend + \ extend + +hi def link embeddedTs NONE + +syn cluster @typescriptAll add=tsxRegion diff --git a/build b/build index 418c251..21bb525 100755 --- a/build +++ b/build @@ -277,6 +277,7 @@ PACKS=" tomdoc:wellbredgrapefruit/tomdoc.vim toml:cespare/vim-toml tptp:c-cube/vim-tptp + tsx:ianks/vim-tsx twig:lumiliet/vim-twig typescript:leafgarland/typescript-vim vala:arrufat/vala.vim diff --git a/config.vim b/config.vim index 7d7d1f2..4e6ecae 100644 --- a/config.vim +++ b/config.vim @@ -79,9 +79,6 @@ augroup filetypedetect "jinja autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja - - "tsx - autocmd BufNewFile,BufRead *.tsx setfiletype typescript.jsx augroup END " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 5ff5033..3fb5107 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -79,9 +79,6 @@ augroup filetypedetect "jinja autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja - - "tsx - autocmd BufNewFile,BufRead *.tsx setfiletype typescript.jsx augroup END " 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 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 +" +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +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 augroup filetypedetect " twig, from twig.vim in lumiliet/vim-twig