First experience with new dune

I have been test driving new dune. Here is the workflow I came up with.

$ dune init proj hello

# Edit dune-project depends
(depends ocaml dune ocaml-lsp-server ocamlformat)

$ dune pkg lock

# Run these commands to build ocamllsp, ocamlformat
$ dune exec ocamllsp
$ dune exec ocamlformat

# export PATH for helix editor
$ export PATH="$PWD/_build/_private/default/.pkg/ocaml-lsp-server/target/bin:$PWD/_build/_private/default/.pkg/ocamlformat/target/bin:$PATH"

Start helix editor at bin/main.ml, and LSP just works.

Is there a way to automate LSP installation and changing PATH like above?

1 Like

It’s in the pipeline Add ocamllsp dev tool by gridbugs · Pull Request #10915 · ocaml/dune · GitHub :wink:

1 Like

The installation can be done by:

opam install ocaml-lsp-server

Normally, you shouldn’t launch the lsp server explicitely. It should be done by the editor.

The PATH of ocamllsp should be like ~/.opam/5.1.0/bin something which is in your default OCaml installation.

If you install a newer swich, ocaml-lsp-server should be reinstalled in the new switch.

This uses opam less workflow with the new unified dune