Add Version Support to `textDocument/publishDiagnostics`
Describe the Bug
When initializing Pyrefly config with publishDiagnostics and versionSupport set to true, I think published diagnostics should return the version key in the response in order to be able to track and match the published diagnostics with the version of the document, in case it is rapidly changing.
I am not sure if this is strictly what the specification dictates, as it is a bit vague in this area. However, that's how it's been working on Pyright.
The reason it's important to me is to be able to "discard" outdated diagnostics with an old version in case they are returned after a new version is published.
e.g.
"publishDiagnostics": {
"versionSupport": True,
"tagSupport": {
"valueSet": [
lsp_types.DiagnosticTag.Unnecessary,
lsp_types.DiagnosticTag.Deprecated,
]
},
}
Also, pass the document versions during the textDocument/didChange event:
{
"textDocument": {
"uri": self._document_uri,
"version": self._document_version,
},
"contentChanges": [{"text": code}],
}
Response from Pyrefly:
DEBUG lsp-types:process.py:281 Server -> Client: {'jsonrpc': '2.0', 'method': 'textDocument/publishDiagnostics', 'params': {'diagnostics': [], 'uri': 'file:///test.py'}}
Same code prepared against basedpyright returns the version appropriately:
DEBUG lsp-types:process.py:281 Server -> Client: {'jsonrpc': '2.0', 'method': 'textDocument/publishDiagnostics', 'params': {'uri': 'file:///test.py', 'version': 2, 'diagnostics': []}}
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
No response
The reason it's important to me is to be able to "discard" outdated diagnostics with an old version in case they are returned after a new version is published.
what system uses this? is it a normal editor over LSP? I always imagine these editors only use the most recent publishDiagnostics
what system uses this? is it a normal editor over LSP? I always imagine these editors only use the most recent publishDiagnostics
I integrate the LSP to a custom Monaco editor component running on a web app. The team at Windmill.dev do something similar.
To do that, I manually communicate with the LSP and resolve the results to be sent down to the client.
See also https://github.com/Mazyod/lsp-python-types
@kinto0 I think @dearfl should be assigned to this issue as they have a PR to fix this.
We can only assign issues to people who have commented on the issue (I guess a github limitation to prevent spam?) Not sure if there's a workaround but maybe the easiest way to solve it would be if @dearfl could leave a comment here
We can only assign issues to people who have commented on the issue (I guess a github limitation to prevent spam?) Not sure if there's a workaround but maybe the easiest way to solve it would be if @dearfl could leave a comment here
sure thing