Minimal VSCode with reason-vscode


#1

I’m hoping to move some coursework in my introductory CS course from Ocaml to Reason, and perhaps to use VSCode as a “development environment”. I put that in quotation marks because the largest programs students will write are perhaps a few hundred lines. They’re used to writing Racket code in DrRacket, where they can type code and easily run it from within the same interface, and it appears that reason-vscode might provide that within VSCode. [Please correct me if I’ve misunderstood this!]

To be clear: I’m an utter novice here. I’ve never used VSCode, and never written a Reason program.

I installed VSCode on my Macbook; i added the reason-vscode extension. I created a new “.re” file on the desktop containing only this:

let a = 4;

and I was hoping to be able to run this minimal program and see something like

val a:int = 4

I tried Debug…Start Without Debugging, and was prompted to “Select Environment”, with Node.js as the only alternative, so I selected that, and got a warning “Cannot find a program to debug.”

In doing this, I was trying to follow the hints given at https://medium.com/@ryyppy/a-quick-look-on-my-reasonml-workflow-with-vscode-637685f9417a, which seemed to suggest “Get VSCode; install the reason-vscode extension; do stuff!”, but it appears that at a bare minimum, there’s an expectation that a bunch of other things are installed. Given how Reason appears to work, some BuckleScript stuff, and Node.js, seem to be a bare minimum.

If someone can help me get a minimal setup working, I’ll produce a document that says how to do it step-by-step (for the benefit of my class) and share it widely, helping avoid stupid questions like this one in the future.

By the way, I’d be completely happy with pointers to other things I can read.


#2

Hi, have you checked out https://sketch.sh/ ? It sounds like that’s exactly what you’re looking for.


#3

What you’re looking for sounds like an REPL. Reason/Ocaml has one and it’s called rtop/utop. But it comes with a terminal interface. sketch.sh is an UI on top of rtop/utop that provides what you need. You should check it out.


#4

sketch.sh does indeed look useful as a way to introduce students to the language with minimal overhead — it could be perfect for a first lab session in which they get to play with ReasonML and compare it to Racket (which they’ll have been using up to that point). But I really would like something a little closer to an IDE. So while I’m grateful for the suggestion, I’ll repeat the question I asked (or a better-phrased version of it):

“Can someone tell me the minimal setup needed to make “VSCode + the reason-vsode extension” actually work for developing small reason programs completely within VSCode?”

I’m working on a mac, but I assume that this is pretty much irrelevant, and I CAN work on a Windows or Linux machine if providing an answer for either of those is easier for some reason. Also, I’d be happy to be given a list of all the reason-related tools you have installed, and then reduce them down myself, if that’s easier for someone to provide.

Thanks in advance for any help.


#5

Gotcha. So for an IDE-like experience in Reason the standard recommendation is to use VSCode + reason-vscode. The main issue with using a more IDE-oriented tooling is that you will need to do an upfront investment in getting students set up and familiarized with a build system. Either they will need to use the BuckleScript tooling, which will produce JavaScript output that will need to be run in a browser or NodeJS, or they will need to use dune, which will produce native output. Either way, each build system will require some getting used to.

So you’ll need to make a decision about which path you want to go.

There are a couple of other factors, like what kind of development workflow you’re looking for. Using dune allows you to load and run parts of the project in a REPL (but as far as I know only with OCaml syntax, not with Reason syntax). Using BuckleScript allows you to run output JS in the NodeJS REPL to test it out. The REPL situation is not very well-developed.


#6

I think that the NodeJS solution is the way to go in our particular context. (It feeds at least a little bit into one later course, and it means avoiding OCaml syntax and its … uh … idiosyncracies, which is part of why I wanted to move to Reason in the first place.)

So assuming that the NodeJS solution is how I’d like to go, what’s involved in going from a basic ReasonML program like my

let a = 4;

to seeing output like

val a:int = 4

in some window in VSCode? I take it that to do such a thing, I need something like a “makefile”, probably in some directory related to the location of my source-code. I’d be happy if someone could give me a pointer to getting such a thing set up for tiny programs like mine, rather than ones that will interact with web pages, etc., and require multiple bits of scaffolding.


#7

The recommended installation and setup steps are covered in https://reasonml.github.io/docs/en/installation . That all assumes that you have NodeJS installed. (A little Reason plug: https://github.com/Schniz/fnm is a nifty tool to manage Node versions.)

VSCode setup is covered in https://reasonml.github.io/docs/en/editor-plugins

The VSCode plugin shows signatures like let a: int = 4 immediately on the line above any binding (in the editor window itself).

For a BuckleScript project (i.e. compile to JavaScript), new project setup is covered in https://bucklescript.github.io/docs/en/new-project


#8

Thanks very much. I’ll try those, and return if I find myself unable to make progress.


#9

It’s a pity CodeSandbox doesn’t support custom extensions and doesn’t include reason-vscode out of the box (which is a little weird given they have a Reason Template. Because CodeSandbox basically is an online version of VS Code and it does run Reason. Note that this sandbox differs very little from what you get creating a sandbox using Reason template. I’ve just thrown away React )

But anyway, going with BuckleScript has an upside of being able to use CodeSandbox as well as VS Code proper, which might prove useful while you’re learning.


#10

Actually you just reminded me that Repl.it supports ReasonML in an IDE-like experience fully online.

@jfh you might try this out, no install required: https://repl.it/languages/reason_nodejs


#11

you can’t get such output when using Bucklescript


#12

Woah :open_mouth: !!!

fnm is great and really fast !