astral-sh / ruff-lsp

A Language Server Protocol implementation for Ruff.
Other
1.31k stars 46 forks source link

Move from open/close/save diagnostics to `textDocument/diagnostics` #279

Open karthiknadig opened 1 year ago

karthiknadig commented 1 year ago

With this you can enable support for whole workspace and related document diagnostics.

dhruvmanila commented 1 year ago

Thanks! The DocumentDiagnosticReportKind.Unchanged feature is nice as it kinda acts like a cache and the editor doesn't need to re-render the diagnostics. Does this mean that refreshing the diagnostic is client's responsibility as this is a pull model?

karthiknadig commented 1 year ago

Yes, client decides when diagnostics is pulled for a file or workspace.

karthiknadig commented 1 year ago

Just wanted to add some bit of info for this:

  1. This adds 3 "reporting scopes"
    1. document level: (default) client will basically call textDocument/diagnostic on each open document.
    2. dependent-document: you have to enable this mode from the server by setting dependent document diagnostic. What happens here is that you would get textDocument/diagnostic for a document, your response can include diagnostic for multiple documents that the said document depends on.
    3. workspace scope: This is a separate request workspace/diagnostic, the result of this request is expected to include all document diagnostics.
  2. You don't control when the diagnostics are reported. the client will always ask for it when it determines this is needed. So things like onType diagnostic might have to be redefined, as the client will decide how often this is called.
dhruvmanila commented 1 year ago

This is useful information. Thanks for sharing!