Skip to content

Feature: Allow users to choose which Dune context to use #1432

@jchavarri

Description

@jchavarri

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions