Closed BerkeleyTrue closed 9 years ago
:+1:
I gave it a try on my own fork: https://github.com/ruyadorno/vim-jsx/tree/detect-filetype
I'm not 100% sure about the implementation but I got it working for my projects :)
Are you just using jsx ext?
yeah... is it bad? :blush: like very, very bad?
now that you mentioned I just saw that in your first message you did stated without the jsx ext
. what are the problems in doing this naive implementation?
I had a bunch of compatibility problems using jsx ext and my vim setup. If I can't figure out how to get this to work I will add a custom pragma.
The way I got around this was to set let g:jsx_pragma_required = 0
. Means its run on every javascript file but it seems to work so far.
@jkimbo Good idea. I will try that.
Presumably grepping for React may not work for files that, e.g., just contain functions which return React components, without defining any? The extension support has been added with the most recent commit.
Is there an harm in having it always on?
@BerkeleyTrue—The syntax regexes are fairly simple and will highlight the latter portion of, e.g., if (w<u) {
as a JSX tag, which breaks highlighting for the rest of the document. I think it's reasonable to "force" a better whitespace style for JSX files for vim-jsx users, but I don't want that to be the default for users who sometimes deal with grungy whitespaceless JS codebases.
It's easy enough to always-enable vim-jsx by just adding let g:jsx_ext_required = 0
somewhere in your ~/.vimrc
or elsewhere in your runtimepath.
Here's what I am using for jsx detection (borrowed mostly from @wincent): https://github.com/lencioni/dotfiles/blob/891897374e096b3f250840f3283033f2b7d8310a/.vim/ftdetect/jsx.vim
Similarly to the ftdetect that comes with vim-jsx, it assumes that .js.jsx
files (could just as easily be .jsx
) are jsx. However, there are some key differences:
React.
to determine if it uses jsx.javascript.jsx
which allows you to have jsx-specific configuration while inheriting javascript configuration.html.jsx
._spec
, Spec
, or -test
, it sets the filetype to javascript.jasmine.jsx
, which allows you to have jasmine-specific configuration as well.What do you think about using this approach? It would allow you to change all of the files in this package from javascript.vim
to jsx.vim
, which would be more nicely scoped.
Facebook is recommending .jsx and are using it internally. I am going to spend a couple of hours getting my vimrc working right with jsx. https://github.com/facebook/react/issues/832
React 0.12 will remove the jsx pragma.
react 0.12-rc
I think possible solutions to detecting a jsx file without the jsx ext should be discussed.
One possible solution is to grep the doc for
React
. I am not the greatest at vimscript so I don't know how feasible this would be.