an-sh / flow-minor-mode

Emacs minor mode for editing flowtype files.
BSD 3-Clause "New" or "Revised" License
47 stars 16 forks source link

No syntax highliting with js2-mode and rjx-mode #8

Open phtrivier opened 7 years ago

phtrivier commented 7 years ago

Is this minor-mode supposed to change syntax highlighting ? I've tried several combinations:

The display is still using default js syntax highlithing (which looks like an error.)

Note that running flow-mode-status works as expected.

an-sh commented 7 years ago

No, this mode doesn't syntax/ident rules. The problem is with the js2-mode parser which requires a strict js syntax without any extensions (but in return gives 100% accurate results). Also flow supports jsx, so fixing j2-mode will be essentially replacing js2-mode Mozilla derived parser with Flow-derived one (means creating yet another one major JavaScript (jsx) mode). web-mode and plain js-mode are better to be used for flow in emacs (in my opinion). Probably there are some workarounds for using js2-mode with flow syntax, but i'm not familiar with anything sensible.

antifuchs commented 7 years ago

So I just looked into how rjsx-mode extends js2-mode, and built a little proof-of-concept flow parsing scheme into js2-mode. It can understand type-annotated variables (with structured types, union/intersection types and a few other things, but no generic or function return types yet).

If you're interested, I can submit this as a pull request - it does result in rather pleasing-looking JS files for me now, but on the other hand, it does reach somewhat deeply into js2-mode via defadvice /:

an-sh commented 7 years ago

Sure, i can look at it (but not sure when i have enough time). As far as i understand this will check if the major mode is js2 mode and active, right?

Fuco1 commented 6 years ago

I've took the work of @antifuchs and packaged and enhanced it here: https://github.com/Fuco1/flow-js2-mode

You might want to include a link in the readme (I link back here as well :)) for people who are looking for the syntax support/fontification.

It's a work in progress but I'd say 70% of the common usage is covered.

an-sh commented 6 years ago

Thanks, added.