Switch jsx provider to amadeus, closes #364

This commit is contained in:
Adam Stankiewicz
2019-03-04 10:46:19 +01:00
parent 4f0bde6d67
commit 2c59360e01
6 changed files with 406 additions and 20 deletions

View File

@@ -568,7 +568,7 @@ endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
augroup filetypedetect
" jsx, from javascript.vim in mxw/vim-jsx:_ALL
" jsx, from javascript.vim in amadeus/vim-jsx
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim ftdetect file
"
@@ -577,20 +577,27 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Whether the .jsx extension is required.
if !exists('g:jsx_ext_required')
let g:jsx_ext_required = 0
endif
" Whether the @jsx pragma is required.
if !exists('g:jsx_pragma_required')
let g:jsx_pragma_required = 0
endif
let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/'
" if g:jsx_check_react_import == 1
" parse the first line of js file (skipping comments). When it has a 'react'
" importation, we guess the user writes jsx
" endif
let s:jsx_prevalent_pattern =
\ '\v\C%^\_s*%(%(//.*\_$|/\*\_.{-}\*/)@>\_s*)*%(import\s+\k+\s+from\s+|%(\l+\s+)=\k+\s*\=\s*require\s*\(\s*)[`"'']react>'
" Whether to set the JSX filetype on *.js files.
fu! <SID>EnableJSX()
" Whether the .jsx extension is required.
if !exists('g:jsx_ext_required')
let g:jsx_ext_required = 0
endif
" Whether the @jsx pragma is required.
if !exists('g:jsx_pragma_required')
let g:jsx_pragma_required = 0
endif
if g:jsx_pragma_required && !exists('b:jsx_ext_found')
" Look for the @jsx pragma. It must be included in a docblock comment
" before anything else in the file (except whitespace).
@@ -598,7 +605,10 @@ fu! <SID>EnableJSX()
endif
if g:jsx_pragma_required && !b:jsx_pragma_found | return 0 | endif
if g:jsx_ext_required && !exists('b:jsx_ext_found') | return 0 | endif
if g:jsx_ext_required && !exists('b:jsx_ext_found') &&
\ !(get(g:,'jsx_check_react_import') && search(s:jsx_prevalent_pattern, 'nw'))
return 0
endif
return 1
endfu