diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index 528ffdb4..8606aba1 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -442,13 +442,13 @@ def lint(self, doc_uri, is_saved): workspace = self._match_uri_to_workspace(doc_uri) document_object = workspace.documents.get(doc_uri, None) if isinstance(document_object, Document): - self._lint_text_document(doc_uri, workspace, is_saved=is_saved) + self._lint_text_document(doc_uri, workspace, is_saved, document_object.version) elif isinstance(document_object, Notebook): self._lint_notebook_document(document_object, workspace) - def _lint_text_document(self, doc_uri, workspace, is_saved): + def _lint_text_document(self, doc_uri, workspace, is_saved, doc_version=None): workspace.publish_diagnostics( - doc_uri, flatten(self._hook("pylsp_lint", doc_uri, is_saved=is_saved)) + doc_uri, flatten(self._hook("pylsp_lint", doc_uri, is_saved=is_saved)), doc_version, ) def _lint_notebook_document(self, notebook_document, workspace): diff --git a/pylsp/workspace.py b/pylsp/workspace.py index c1b32f20..f047ed08 100644 --- a/pylsp/workspace.py +++ b/pylsp/workspace.py @@ -176,10 +176,18 @@ def update_config(self, settings): def apply_edit(self, edit): return self._endpoint.request(self.M_APPLY_EDIT, {"edit": edit}) - def publish_diagnostics(self, doc_uri, diagnostics): + def publish_diagnostics(self, doc_uri, diagnostics, doc_version=None): + params = { + "uri": doc_uri, + "diagnostics": diagnostics, + } + + if doc_version: + params["version"] = doc_version + self._endpoint.notify( self.M_PUBLISH_DIAGNOSTICS, - params={"uri": doc_uri, "diagnostics": diagnostics}, + params=params, ) @contextmanager