vscode-ocaml-platform icon indicating copy to clipboard operation
vscode-ocaml-platform copied to clipboard

Allow selection of Dune context

Open jchavarri opened this issue 1 year ago • 1 comments

Fixes #1432.

Dependencies

This PR relies on features being added in ocamllsp and dune:

Description

The PR adds a new select-dune-context command that will show the list of available Dune contexts for the user to choose from. Once a selection is done, the setting will be stored in a new config ocaml.dune.context.

Every time the value of the context changes, the LSP server will be killed and a new instance will be created, passing --context flag as param (this param is added in the PR referred above).

Demo

In the demo below, we are switching between a context melange and the default one. One can observe how all the features in the editor like go to definition, codelenses or PPXs will be shown from the perspective of the currently selected context:

editor-melange-context

Future improvements

Right now, only a single instance of the LSP server is running, which means that for files that are not in the currently selected context, the editor will show the infamous No config found for file foo.ml. Try calling 'dune build' error. In the future, we can improve this by runnning as many LSP server instances as Dune contexts exist, so that the VSCode extension can inspect the result of each, and choose the data from the one that is not failing.

jchavarri avatar Apr 18 '24 08:04 jchavarri

I talked to @andreypopp and he suggested to remove the duneContexts protocol command, and instead call dune describe contexts directly from the vscode extension. I applied these changes in https://github.com/ocamllabs/vscode-ocaml-platform/pull/1449/commits/9d348689874890487734bb20b02d1daeb282d7c2 and its companion commit https://github.com/ocaml/ocaml-lsp/pull/1238/commits/9ada8752ddf9fefd220699fcb530491df7fff06d.

jchavarri avatar May 03 '24 10:05 jchavarri