flow-minor-mode icon indicating copy to clipboard operation
flow-minor-mode copied to clipboard

No syntax highliting with js2-mode and rjx-mode

Open phtrivier opened this issue 8 years ago • 5 comments

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

  • js2-mode and flow-minor-mode
  • js2-mode and rjsx-mode and flow-minor-mode

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

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

phtrivier avatar Apr 18 '17 11:04 phtrivier

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.

an-sh avatar Apr 18 '17 20:04 an-sh

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

antifuchs avatar May 29 '17 06:05 antifuchs

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?

an-sh avatar Jun 03 '17 07:06 an-sh

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.

Fuco1 avatar Nov 29 '17 13:11 Fuco1

Thanks, added.

an-sh avatar Nov 29 '17 17:11 an-sh