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

fix: refresh merlin configs after dune build #853

Merged

Conversation

rgrinberg
Copy link
Member

@rgrinberg rgrinberg commented Sep 1, 2022

When dune finishes a build, merlin configuration might not be correct and it's useful to reload it and give users fresh diagnostics. Of course, this requires us throwing away some diagnostic work that isn't necessarily stale, but it's better to be slow than give false positives to the user.

@ulugbekna ulugbekna self-assigned this Sep 3, 2022
@ulugbekna
Copy link
Collaborator

ulugbekna commented Sep 8, 2022

It seems like we're "set"ting the new diagnostics for merlin docs but don't send them? If I add Diagnostics.send diagnostics All to progress_loop, the new diagnostics get sent and user sees updated diagnostics in their files automatically.

That's very cool! I was thinking of this feature, but I imagined we need to update diagnostics only for reverse deps of the module that's being edited, but your solution seems good.

@rgrinberg rgrinberg force-pushed the ps/rr/fix__refresh_merlin_configs_after_dune_build branch from 15233f9 to f02c3f4 Compare September 12, 2022 13:58
@rgrinberg
Copy link
Member Author

It seems like we're "set"ting the new diagnostics for merlin docs but don't send them? If I add Diagnostics.send diagnostics All to progress_loop, the new diagnostics get sent and user sees updated diagnostics in their files automatically.

Thanks. This is now fixed.

That's very cool! I was thinking of this feature, but I imagined we need to update diagnostics only for reverse deps of the module that's being edited, but your solution seems good.

It turns this is problematic to implement with dune currently. One needs to keep a set of the dependency closure for every module and keep it updated. It's not trivial but if this solution isn't good enough, we'll have to go this way.

ps-id: 0f3e313d-219b-4dcc-bcb5-0a2c6937e1f1
@rgrinberg rgrinberg force-pushed the ps/rr/fix__refresh_merlin_configs_after_dune_build branch from f02c3f4 to 6116f0e Compare September 12, 2022 16:18
@rgrinberg rgrinberg merged commit 88e2fbe into master Sep 12, 2022
@ulugbekna
Copy link
Collaborator

If the file being edited is an implementation file and given its interface file exists, would it make sense that we only update diagnostics for its interface file if it's open? But if the impl file being edited doesn't have an interface file, then we update diagnostics to all files.

@rgrinberg
Copy link
Member Author

I'm not sure I understand the optimization. Can you give an example?

@ulugbekna
Copy link
Collaborator

ulugbekna commented Sep 12, 2022

I meant to say that, to my understanding, OCaml can avoid compiling reverse dependencies of a compilation unit, if the unit's interface hasn't changed. Consequently, if we could determine that the re-build was triggered by edits to an implementation file, we could only update diagnostics for its interface file and not for other files, which would not anyway have any changes in their diagnostics from merlin because they depend on the unchanged interface file. For example, if there's foo.ml that depends on bar.mli, then edits to bar.ml should only update diagnostics for bar.mli but not foo.ml because nothing changed from foo.ml's perspective.

It's not clear, however, how to determine whether the re-build was triggered by changes to an implementation file. We could

  • either rely on dune to tell us what triggered the re-build
  • or see what files were edited (olsp received file-edit notifications for) between two builds of a single dune instance (in this case, however, we assume that olsp receives notifications for all file changes, which may not be the case in case of, e.g., dune promotions)

Does this help?

@rgrinberg
Copy link
Member Author

Okay, I understand. Note that we don't need to worry about any of these details since they're all reflected in the dependency graph dune provides us with. We just need a better way to work with it.

rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Oct 15, 2022
CHANGES:

## Features

- Code action for inlining let bindings within a module or expression. (ocaml/ocaml-lsp#847)

- Tag "unused code" and "deprecated" warnings, allowing clients to better
  display them. (ocaml/ocaml-lsp#848)

- Refresh merlin configuration after every dune build in watch mode (ocaml/ocaml-lsp#853)

## Fixes

- Respect `showDocument` capabilities. Do not offer commands or code actions
  that rely on this request without client support. (ocaml/ocaml-lsp#836)

- Fix signatureHelp on .mll files: avoid "Document.dune" exceptions
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.

None yet

2 participants