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

Clear diagnostics for non-project files #271

Merged
merged 6 commits into from
Oct 26, 2020
Merged

Conversation

ulugbekna
Copy link
Collaborator

When one opens a source file of a library they use (with go-to-definition, for example), merlin reports errors in that file. When the file is closed, the errors remain in the problems pane (see the screenshot). This PR clears the reported errors when such a non-project source is closed. I define non-project source file as a file with URI that contains ".opam", "_opam", or "_esy".

image

@ulugbekna ulugbekna requested a review from rgrinberg October 24, 2020 15:26
@ulugbekna
Copy link
Collaborator Author

MacOS tests are failing for me locally but even with master -- not sure why.

lsp/src/import.ml Outdated Show resolved Hide resolved
@rgrinberg
Copy link
Member

When one opens a source file of a library they use (with go-to-definition, for example), merlin reports errors in that file. When the file is closed, the errors remain in the problems pane (see the screenshot)

That's the bigger problem I think. When a document is closed we should republish the diagnostics without the closed file.

@ulugbekna
Copy link
Collaborator Author

When a document is closed we should republish the diagnostics without the closed file.

I am not sure about this because having errors for project files to persist after they are closed:

  • helps to see that there are still errors that may affect the other files that the user switch to work on (for example, to keep a note to come back to that file to fix the issues -- vscode marks filenames red of files that contain errors)
  • signals that the build will likely fail
  • is "recommended" by lsp spec:

Diagnostics are “owned” by the server so it is the server’s responsibility to clear them if necessary. The following rule is used for VS Code servers that generate diagnostics:

  • if a language is single file only (for example HTML) then diagnostics are cleared by the server when the file is closed.
  • if a language has a project system (for example C#) diagnostics are not cleared when a file closes. When a project is opened all diagnostics for all files are recomputed (or read from a cache).

@rgrinberg
Copy link
Member

The spec recommendation certainly makes sense if diagnostics are project wide, but our diagnostics are local to a single compilation unit. Let's consider what it would take for the user to clear out stale diagnostics: he would have to open every stale file and recompute them. That seems like a poor experience to me, and that is not how merlin did diagnostics for vim and emacs in its traditional front end.

We will have project wide diagnostics in the future, but they will come from dune rather than merlin. In this case, it would make sense to keep them lingering around. That's because we'll know for sure they're applicable, and we'll be able to clean them up automatically once they are stale.

@ulugbekna
Copy link
Collaborator Author

ulugbekna commented Oct 25, 2020 via email

lsp/src/dune Outdated Show resolved Hide resolved
ulugbekna and others added 3 commits October 26, 2020 12:09
Signed-off-by: Rudi Grinberg <[email protected]>
There's no need to execute LSP related stuff in it

Signed-off-by: Rudi Grinberg <[email protected]>
@rgrinberg
Copy link
Member

I must have misread the diff in the web UI. Code looks good. Some minor adjustments:

  • I got rid of @@. It's confusing to read the extend of the functions it applies
  • I fixed the code to wait for canceling the document on close
  • I moved more code outside of the merlin thread. We should only run code that modifies the typechecker state in here.
  • I added a CHANGES entry.

@rgrinberg rgrinberg merged commit 398c425 into ocaml:master Oct 26, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Nov 16, 2020
CHANGES:

## Features

- Add keyword completion

- Add go to declaration functionality to jump to a value's specification in a
  .mli file (ocaml/ocaml-lsp#294)

## Fixes

- ocaml/ocaml-lsp#245: correctly use mutexes on OpenBSD (ocaml/ocaml-lsp#264)

- ocaml/ocaml-lsp#268: Do not use vendored libraries when building the lsp package (ocaml/ocaml-lsp#260)

- ocaml/ocaml-lsp#271: Clear diagnostics when files are closed

- Disable non-prefix completion. There's no reliably way to trigger it and it
  can be slow.
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.

2 participants