The formatter/converter for the new syntax is available for testing


#1

This new bsc compiler api for the new syntax serves two purposes:

  • formatting a new syntax file (.res and .resi).
  • converting over existing OCaml/Reason file.

Assuming you have npm install bs-platform@8.1.1 installed, do: path/to/bsc -fmt YourFile. The api knows to either just format or to convert OCaml/Reason syntax over, depending on yourFile's extension.

Before:


After:

This command line flag isn’t stable yet; it’s intended for manual usage, to gather feedback. The conversion from Reason to the new syntax happens to be a nontrivial amount of work under the hood, thus our cautiousness. Please try them on your complex files in your codebase and see if you get any error. Here’s our tip:

  • Make sure you’ve already checked in your .bs.js output like we recommended for the project setup. If you haven’t, that’s fine too: just create a new branch in your version control, run the build and check in the BS js output (probably by un-ignoring *.bs.js from your .gitignore).
  • Run e.g. node_modules/.bin.bsc -fmt YourFile.re > YourFile.res.
  • Run mv YourFile.re YourFile.re.backup, to make the build ignore your old file.
  • Run the build. Check if there’s any new .bs.js output changes. If not, then congratulations, you’re done!
  • If there are nontrivial output changes, please file an issue here.

We’ll be releasing a more fully-featured conversion tool and in-editor formatter afterward, but there’s nothing wrong with converting your project over now if you’ve detected no error. One fewer thing to do in the future.


#2

:+1:

Is it possible to change the print width? Like it used to be with (bs)refmt -w?


#3

That image is not very clear. It doesn’t have any padding (so hard to read), and I don’t see what is the actual binary. I just see calling cat with three files? Where can we find the binary to convert between syntaxes?


#4

npx bsc -fmt xx.{ml,re,res} assuming you have the dev version(8.1.1) installed


#5

Ah ok. I didn’t parse the text correctly.


#6

Woooo! Way to go @bobzhang. Thank you!


#7

This code throws a lot of errors under 8.1.1 but in 8.1.0 works fine https://github.com/mrkaspa/padlock2


#8

The syntax is being finalized. The difference on the project is probably list[...] becoming list{...}. Doing the change manually, or using the automatic converter on the old files e.g. ./node_modules/.bin/bsc -fmt src/Main.re should take care of that.


#9

Do we know when the editor support in vscode will work for this new syntax? As a reasonml learner, it’s much tougher to use this new syntax with the current tooling support. Although I get syntax highlighting in vscode, I don’t have the things I get in the old syntax like highlights of variable types and things like that.

I am using the latest vscode and reason-vscode plugin and bucklescript 8.1.1.


#10

Good question! @chenglou, do you have official plans around this? Here’s what I understand the situation and options to be:

  • The current Reason Lanugage Server has gotten into a state where it’s quite difficult to fix and modify. It’s designed to work for both Bucklescript and native, and the tooling to work on the server itself has gotten pretty tricky to set up correctly, from my experiences.
  • Though the current language server has some nice features, a lot of it was hacked together in one large effort by Jared, but not changed much since then. I’ve spent hours attempting to add features, only to realize that I broke some other functionality when I added the new features.
  • The current language server doesn’t seem to be actively maintained. I don’t think there’s a product owner who’s active in the community right now. There are a huge number of issues and pull-requests that, as far as I know, go un-adressed.
  • There are language server tools for OCaml that could work with the new syntax, but support for using those tools with Reason was abandoned with the onset of the current RLS.

So, as far as options go:

  • The current RLS could be refactored or re-written, which would be quite a significant task. I believe it relies specifically on syntax for Reason v3 when triggering completions at least, and probably in a good number of other areas as well.
  • A new, lightweight language server could be written specifically for the new syntax and Bucklescript. This codebase could be designed from the beginning with contributors in-mind, and a clear process for how improvement PRs would be addressed and merged or closed. (this is the option that I am personally for, even though it wouldn’t forward the integration between native and BSB)
  • Some changes could be made to allow the existing OCaml and Merlin plugins to support the new Bucklescript syntax, and re-use the work already done for those platforms. (Heavier weight, would require more dependencies to install and operate, and I think doesn’t have support for Windows? This is the option I understand the least)

No pressure to make a decision or provide an answer right now, but I’m curious if you have some opinion or direction to offer.


#11

A dumb question: won’t it widen the rift created by a new syntax and make switching from Reason-as-anOCaml-frontend to bs-flavored-Reason kind of a one way road?