Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --context flag of dune ocaml-merlin #1238

Closed

Conversation

jchavarri
Copy link
Contributor

@jchavarri jchavarri commented Apr 1, 2024

This PR integrates two new Dune commands into the LSP server. See related issue vscode-ocaml-platform#1432.

Dependencies and related PRs

This PR relies on features being added in dune#10324.

It also unblocks the feature implemented in vscode-ocaml-platform#1449. A screen capture demo is shown in that issue.

Description

  • Add a new request ocamllsp/getDuneContexts that will return the list of available Dune contexts in the workspace (through the newly added dune describe contexts subcommand)
  • Introduce a new command line flag --context in the server. This flag, when present, will be passed through to the dune ocaml-merlin instance being created.

@jchavarri jchavarri force-pushed the dune-merlin/add-getsetcontexts branch from 3eea746 to 530c182 Compare April 10, 2024 15:29
@jchavarri jchavarri force-pushed the dune-merlin/add-getsetcontexts branch from cdefa22 to 1a778fb Compare April 15, 2024 07:05
@jchavarri jchavarri changed the title dune, merlin: add integration with get/set contexts commands Add getDuneContexts method and spawn a new ocaml-merlin process per Dune context Apr 15, 2024
@jchavarri jchavarri force-pushed the dune-merlin/add-getsetcontexts branch from 444095b to 6ed35fe Compare April 17, 2024 16:43
@jchavarri jchavarri force-pushed the dune-merlin/add-getsetcontexts branch from 6ed35fe to ba7b147 Compare April 18, 2024 07:50
@jchavarri jchavarri changed the title Add getDuneContexts method and spawn a new ocaml-merlin process per Dune context Add getDuneContexts method and --context flag Apr 18, 2024
@jchavarri jchavarri marked this pull request as ready for review April 18, 2024 08:10
ocaml-lsp-server/docs/ocamllsp/duneContexts-spec.md Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
ocaml-lsp-server/src/merlin_config.ml Outdated Show resolved Hide resolved
ocaml-lsp-server/src/ocaml_lsp_server.ml Outdated Show resolved Hide resolved
())
| Some dune -> (
let describe =
"DUNE_CONFIG__GLOBAL_LOCK=disabled " ^ Fpath.to_string dune
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DUNE_CONFIG__GLOBAL_LOCK=disabled
^ :(

but the question is — is dune describe contexts command's output stable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the need for DUNE_CONFIG__GLOBAL_LOCK as a bug / limitation of Dune, rather than a hack in this PR. The main issue is that Dune doesn't differentiate between commands that write in _build vs commands that only read. So it will always lock the folder regardless. I opened an issue to discuss making the lock mechanism smarter: ocaml/dune#10430

but the question is — is dune describe contexts command's output stable?

This subcommand is being added in the companion PR ocaml/dune#10324. It only outputs the names of the available contexts, so it shouldn't need to change over time.

@jchavarri
Copy link
Contributor Author

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 9ada875 and its companion commit ocamllabs/vscode-ocaml-platform@9d34868.

Copy link
Member

@andreypopp andreypopp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

ocaml-lsp-server/src/merlin_config.ml Outdated Show resolved Hide resolved
ocaml-lsp-server/src/merlin_config.ml Outdated Show resolved Hide resolved
@andreypopp andreypopp changed the title Add getDuneContexts method and --context flag Support --context flag of dune ocaml-merlin May 6, 2024
@jchavarri
Copy link
Contributor Author

Thanks for the reviews @andreypopp. From my side, there's nothing else to add to this PR. Also, the parent PR in dune ocaml/dune#10324 has been merged, and it should be included in next release 3.16.

@voodoos
Copy link
Collaborator

voodoos commented Jun 11, 2024

@jchavarri is it the responsibility of the editor plugin to not use that flag if the installed dune version does not understand it (< 3.16)

@@ -8,6 +8,8 @@

- Support folding of `ifthenelse` expressions (#1031)

- Add `--context` flag (#1238)
Copy link
Collaborator

@voodoos voodoos Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add a bit more context here, at least define what "context" refers to here.

@voodoos
Copy link
Collaborator

voodoos commented Jun 26, 2024

@jchavarri is this PR ready ?

What will happen if the installed dune does not understand that flag ?

@rgrinberg
Copy link
Member

I don't think this is needed anymore. Turns out that contexts alone aren't good enough for melange support.

@rgrinberg rgrinberg closed this Jun 26, 2024
@jchavarri
Copy link
Contributor Author

jchavarri commented Jun 28, 2024

@rgrinberg Should ocaml/dune#10324 be reverted? That PR was added exclusively to support this use case. If context selection is not useful for any other use cases besides melange, then it probably doesn't make much sense to keep the code added in that PR.

@jchavarri jchavarri deleted the dune-merlin/add-getsetcontexts branch June 28, 2024 09:03
@rgrinberg
Copy link
Member

Yes, there's probably no point to it. Though I think we should focus on implementing the new feature and what would that look like. We can clean things up in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants