mxw / vim-jsx

React JSX syntax highlighting and indenting for vim.
1.59k stars 95 forks source link

React 0.12 will remove the pragma. #19

Closed BerkeleyTrue closed 9 years ago

BerkeleyTrue commented 10 years ago

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.

ruyadorno commented 10 years ago

:+1:

ruyadorno commented 10 years ago

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 :)

BerkeleyTrue commented 10 years ago

Are you just using jsx ext?

ruyadorno commented 10 years ago

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?

BerkeleyTrue commented 10 years ago

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.

jkimbo commented 10 years ago

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.

BerkeleyTrue commented 10 years ago

@jkimbo Good idea. I will try that.

mxw commented 10 years ago

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.

BerkeleyTrue commented 10 years ago

Is there an harm in having it always on?

mxw commented 10 years ago

@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.

lencioni commented 10 years ago

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:

  1. For .js and .html files, it searches through the beginning of the file for React. to determine if it uses jsx.
  2. For .js files that use React, it sets the filetype to javascript.jsx which allows you to have jsx-specific configuration while inheriting javascript configuration.
  3. For .html files that use React, it sets the filetype to html.jsx.
  4. If the filename ends in _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.

BerkeleyTrue commented 9 years ago

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