We are currently experimenting with separate Melange and OCaml libraries and place them in different Dune contexts, in order to improve the developer experience (see melange-re/melange#694).
Under this multi-context setup, it would be useful as a user to select which Dune context to use in VSCode for code definitions, types and errors.
We are putting out this proposal to gather feedback from maintainers, and if accepted, make sure the implementation plan is ok.
Current status
It is currently possible to choose the context by editing dune-workspace files and adding (merlin) to the context we want to work on, but this has a few downsides:
- It requires to manually edit
dune-workspace every time one wants to switch context
- Can lead to unwanted changes in this file when using git or other source versioning tools
- There is some bug where dune
ocaml-merlin won't pick up the new context straight away, so it shows errors like :No config found for file foo.ml. Try calling 'dune build' until one restarts the whole VSCode window
Proposal
To improve the experience, the proposal is to add a new command select-context to this extension, which will show users a list of contexts to choose from, and record their choice in vscode settings (similar to the current experience with sandbox selection in select-sandbox).
Implementation
For this to happen, besides the new VSCode command select-context, we will have to add a few other pieces in ocaml-lsp-server and Dune's ocaml-merlin:
ocaml-lsp-server
- Add a new request
ocamllsp/getDuneContexts to the lsp server. This request will resolve to calling ocaml-merlin behind the scenes (see below)
- Add a new handling logic in
didChangeConfiguration for a newly added duneContext config. This handling will forward the change to ocaml-merlin (see below)
ocaml-merlin
- Add new command
GetContexts that returns a list of available contexts in the current workspace, so that they can be sent through ocamllsp/getDuneContexts and shown in a list inside VSCode extension UI
- Add a new command
SetContext that allows to define the current context, which will be called from ocaml-lsp-server didChangeConfiguration handler
Does the above plan make sense? Thanks!
We are currently experimenting with separate Melange and OCaml libraries and place them in different Dune contexts, in order to improve the developer experience (see melange-re/melange#694).
Under this multi-context setup, it would be useful as a user to select which Dune context to use in VSCode for code definitions, types and errors.
We are putting out this proposal to gather feedback from maintainers, and if accepted, make sure the implementation plan is ok.
Current status
It is currently possible to choose the context by editing
dune-workspacefiles and adding(merlin)to the context we want to work on, but this has a few downsides:dune-workspaceevery time one wants to switch contextocaml-merlinwon't pick up the new context straight away, so it shows errors like:No config found for file foo.ml. Try calling 'dune build'until one restarts the whole VSCode windowProposal
To improve the experience, the proposal is to add a new command
select-contextto this extension, which will show users a list of contexts to choose from, and record their choice in vscode settings (similar to the current experience with sandbox selection inselect-sandbox).Implementation
For this to happen, besides the new VSCode command
select-context, we will have to add a few other pieces in ocaml-lsp-server and Dune'socaml-merlin:ocaml-lsp-server
ocamllsp/getDuneContextsto the lsp server. This request will resolve to callingocaml-merlinbehind the scenes (see below)didChangeConfigurationfor a newly addedduneContextconfig. This handling will forward the change toocaml-merlin(see below)ocaml-merlin
GetContextsthat returns a list of available contexts in the current workspace, so that they can be sent throughocamllsp/getDuneContextsand shown in a list inside VSCode extension UISetContextthat allows to define the current context, which will be called from ocaml-lsp-serverdidChangeConfigurationhandlerDoes the above plan make sense? Thanks!