lsp icon indicating copy to clipboard operation
lsp copied to clipboard

WIP: Add LSP pull diagnostic commands

Open berggeist opened this issue 9 months ago • 4 comments

LSP specification has introduced with version 3.17 new commands, which allow the client to pull diagnostics from the server. Earlier versions of the LSP specification just allowed the notification of diagnostics from the server to the client. This methods are increasingly implemented by new LSP servers. In this first commit just the minimum set of changes has been added for : 'textDocument/diagnostic'. Further commands like 'workspace/diagnostic' and 'workspace/diagnostic/refresh' would be work in progress.

Links to the LSP specification:

What has been implemented so far:

  • [x] Taking care whether a LSP server has the feature diagnostic, i.e. is able to act as isDiagnosticProvider
  • [x] A new command :LspDiagPull that requests the set of diagnostics for the current buffer from all active LSP servers. This command might be used as part of an autocmd.
  • [x] The asynchronously requested diagnostics are provided to the exisiting implementation within the file autoload/lsp/diag.vim for merging with other known diagnostics.
  • [x] Related documents are now being processed, e.g. if a change in one file generates diagnostics in another file.
  • [x] Workspace diagnostics are now implemented by processing all diagnostics for affected files within the project
  • [x] Two new commands have been introduced:
    • LspDiagPull = Pull document diagnostics from the server for the currently active buffer
    • LspDiagPullWorkspace = Pull workspace diagnostics from the server
  • [x] A new user event "LspWorkspaceDiagnosticRefresh" has been introduced, which is raised when a workspace/refresh is being notified from the server to the client

What would be still work in progress:

  • [ ] Decide whether it is needed and feasible to obtain a cache for all versions of received diagnostics (this would be an improvement for an efficient reply of unchanged diagnostics by the server)
  • [ ] Improve handling of related documents
  • [ ] Better error handling
  • [ ] Documentation

It is still not clear how to cope with the fact that the same server could provide diagnostics either by pull request and at the same time as notification.

berggeist avatar May 18 '25 16:05 berggeist

Hello @yegappan ,

unfortunately the tests for this pull request fail, because in my understanding the function foreach is unknown. Should I rewrite the code, in order to avoid the foreach function, or what would be a proper solution for this?

Thanks in advance for your reply!

berggeist avatar Jun 12 '25 17:06 berggeist

The foreach function is available only in recent versions of Vim. The older 9.x version doesn't have this function. Can you rewrite the code without using the foreach function?

yegappan avatar Jun 14 '25 01:06 yegappan

The foreach function is available only in recent versions of Vim. The older 9.x version doesn't have this function. Can you rewrite the code without using the foreach function?

Thank you for your reply, I will fix this accordingly in the next draft version.

berggeist avatar Jul 19 '25 08:07 berggeist

Is this PR ready or are you still working on it?

yegappan avatar Oct 01 '25 05:10 yegappan