I have heard a lot of complaints about lack of editor integration or flaky editor tooling in the Reason community. At my previous job we had ~3000 modules and ~80k LOC. I'll admit that we were not very vigilant with .rei files or keeping our inter module dependencies really clean so this slowed both bsb and especially reason-language-server down a lot.
In fact so much that people couldn't use reason-language-server anymore on 15" MacBook Pros.
I myself have always used a Merlin based setup since I joined the Reason eco system before reason-language-server, and in our project my setup had never failed. Therefor I went on a quest of setting up 3 of the major editors (Emacs, Vim and VSCode) and documenting how to get them working with merlin to make sure that everyone could still work on our project despite it's size.
The editor setups listed below have all been tested in the last 6 months, but I am basing some of the instructions on old documentation that I had and my memory. So if something doesn't work listed here I might have forgotten some steps.
I do know that Emacs with use-package works from this document, since that is the setup that I use day to day.
- brew
- opam - The OCaml Package Manager
brew install opam
opam init
- Switch to correct OCaml compiler
opam switch create 4.06.1
(latest bucklescript uses 4.06, for Bucklescript <= 5.x use 4.02.3)
- Install merlin - Context sensitive completion for OCaml in Vim and Emacs
opam install merlin
- Install reason
opam install reason
- Eval the opam setup
eval $(opam env)
- For convenience put this into your
.zshrc
or.bashrc
or.bashprofile
based on what you use.
- Install this plugin https://marketplace.visualstudio.com/items?itemName=freebroccolo.reasonml
- Make sure to run VSCode from terminal in
code .
in your source folder - Using project local refmt (optional)
- Add
/node_modules/.bin
to your $PATH variable - Add this to VSCode settings.json file
"reason.path.refmt": "bsrefmt"
- Add
- Install
emacs-plus
brew tap d12frosted/emacs-plus
brew install emacs-plus
brew linkapps emacs-plus
- See more https://github.com/d12frosted/homebrew-emacs-plus
- Make sure to checkout
develop
branch of spacemacs - Install reason layer by adding
(reasonml :variables reason-auto-refmt t)
todotspacemacs-configuration-layers
-
Prevent backticks from being auto closed (useful for polymorphic variants since they don't have a closing backtick)
-
(eval-after-load 'smartparens '(progn (sp-pair "`" nil :actions :rem)))
-
-
Set project version of refmt (since opam version is not updated as frequently)
-
(defun shell-cmd (cmd) "Returns the stdout output of a shell command or nil if the command returned an error" (car (ignore-errors (apply 'process-lines (split-string cmd))))) (let* ((refmt-bin (or (shell-cmd "which bsrefmt") (shell-cmd "which refmt")))) (when refmt-bin (setq refmt-command refmt-bin)))
-
-
Add merlin support
(use-package merlin)
- Add reason-mode with format on save
(use-package reason-mode
:config
(add-hook 'reason-mode-hook (lambda ()
(add-hook 'before-save-hook 'refmt-before-save)
(merlin-mode)))
- Install coc (instructions here)
- Install ocaml-lsp or ocaml-language-server
- ocaml-lsp
- ocaml-language-server
- I have heard that people prefer ocaml-lsp but I've tested both and both are fantastic projects
- Follow instructions here on how to configure your chosen language server.