Running OCaml files straight from VS Code

Hi everyone, I’m very glad to introduce a new feature in VSCode OCaml Platform in the release 2.4.0. This work was implemented by Tarides and funded by the OCaml Software Foundation.

A “Run” button has been added to the editor bench. Clicking it opens a dropdown listing executables discovered in your current workspace. This feature was originally targeted at university professors and students, but it can be useful for everyone to quickly debug.

The way executables are discovered depends on the workspace setup. If the user uses Dune and has a dune-project file at the root of the workspace, we take advantage of Dune API to retrieve the list of defined executables and to launch the chosen executable via a basic dune exec ./file. Otherwise, if Dune is not detected as the project builder, the displayed list contains all .ml files discovered in the current workspace, and they are executed with the OCaml bytecode interpreter.

Each time an executable is run, its output is displayed in a dedicated VS Code terminal.

Feedback and bug reports are very welcome!

13 Likes