pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

Add Version Support to `textDocument/publishDiagnostics`

Open Mazyod opened this issue 4 months ago • 5 comments

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

Mazyod avatar Jul 31 '25 05:07 Mazyod

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

kinto0 avatar Sep 16 '25 20:09 kinto0

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

Mazyod avatar Sep 17 '25 05:09 Mazyod

@kinto0 I think @dearfl should be assigned to this issue as they have a PR to fix this.

DanielNoord avatar Nov 28 '25 21:11 DanielNoord

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

yangdanny97 avatar Nov 29 '25 15:11 yangdanny97

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

dearfl avatar Nov 30 '25 00:11 dearfl