zed icon indicating copy to clipboard operation
zed copied to clipboard

Rework project diagnostics to prevent showing inconsistent state

Open maxbrunsfeld opened this issue 10 months ago • 1 comments

For a long time, we've had problems where diagnostics can end up showing up inconsistently in different views. This PR is my attempt to prevent that, and to simplify the system in the process. There are some UX changes.

Diagnostic behaviors that have not changed:

  • In-buffer diagnostics update immediately when LSPs send diagnostics updates.
  • The diagnostic counts in the status bar indicator also update immediately.

Diagnostic behaviors that this PR changes:

  • [x] The tab title for the project diagnostics view now simply shows the same counts as the status bar indicator - the project's current totals. Previously, this tab title showed something slightly different - the numbers of diagnostics currently shown in the diagnostics view's excerpts. But it was pretty confusing that you could sometimes see two different diagnostic counts.

  • [x] The project diagnostics view never updates its excerpts while the user might be in the middle of typing it that view, unless the user expressed an intent for the excerpts to update (by e.g. saving the buffer). This was the behavior we originally implemented, but has changed a few times since then, in attempts to fix other issues. I've restored that invariant.

    Times when the excerpts will update:

    • diagnostics are updated while the diagnostics view is not focused
    • the user changes focus away from the diagnostics view
    • the language server sends a work done progress end message for its disk-based diagnostics token (i.e. cargo check finishes)
    • the user saves a buffer associated with a language server, and then a debounce timer expires
  • [ ] The project diagnostics view indicates when its diagnostics are stale. States:

    • when diagnostics have been updated while the diagnostics view was focused:
      • the indicator shows the number of diagnostics that have changed, and contains a 'refresh' icon
      • clicking the indicator updates the excerpts
    • when diagnostics have been updated, but a file has been saved, so that the diagnostics will soon update, the indicator says "checking..."

With these UX changes, the only 'complex' part of the our diagnostics presentation is the Project Diagnostics view's excerpt management, because it needs to implement the deferred updates in order to avoid disrupting the user while they may be typing. I want to take some steps to reduce the potential for bugs in this view.

  • [x] Reduce the amount of state that the view uses, and simplify its implementation
  • [ ] Add a randomized test that checks the invariant that a mutated diagnostics view matches a freshly computed diagnostics view

maxbrunsfeld avatar Apr 24 '24 05:04 maxbrunsfeld

Warnings
:warning:

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- (Added|Fixed|Improved) ... ([#<public_issue_number_if_exists>](https://github.com/zed-industries/zed/issues/<public_issue_number_if_exists>)).

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by :no_entry_sign: dangerJS against e5a9565fa102a2f86c54491413e9ae6b84ab8573

zed-industries-bot avatar Apr 24 '24 05:04 zed-industries-bot