From 9c70cb79d69de013e07643baa66d947e8bc05511 Mon Sep 17 00:00:00 2001 From: Dylan Mayor <36193755+Dylmay@users.noreply.github.com> Date: Fri, 31 May 2024 20:01:03 +0000 Subject: [PATCH 1/4] versions --- pylsp/python_lsp.py | 3 ++- pylsp/workspace.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index 528ffdb4..62c6f2ef 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -447,8 +447,9 @@ def lint(self, doc_uri, is_saved): self._lint_notebook_document(document_object, workspace) def _lint_text_document(self, doc_uri, workspace, is_saved): + document_object = workspace.documents.get(doc_uri, 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)), document_object.version, ) def _lint_notebook_document(self, notebook_document, workspace): diff --git a/pylsp/workspace.py b/pylsp/workspace.py index c1b32f20..1dd46bd9 100644 --- a/pylsp/workspace.py +++ b/pylsp/workspace.py @@ -176,10 +176,10 @@ 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): self._endpoint.notify( self.M_PUBLISH_DIAGNOSTICS, - params={"uri": doc_uri, "diagnostics": diagnostics}, + params={"uri": doc_uri, "diagnostics": diagnostics, "version": doc_version}, ) @contextmanager From 8405b9fcac5404914a3f19329baefeb72b9200ce Mon Sep 17 00:00:00 2001 From: Dylan Mayor <36193755+Dylmay@users.noreply.github.com> Date: Tue, 4 Jun 2024 11:37:02 +0100 Subject: [PATCH 2/4] tidier versioning --- pylsp/python_lsp.py | 7 +++---- pylsp/workspace.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index 62c6f2ef..cee706d2 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -442,14 +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, doc_version) elif isinstance(document_object, Notebook): self._lint_notebook_document(document_object, workspace) - def _lint_text_document(self, doc_uri, workspace, is_saved): - document_object = workspace.documents.get(doc_uri, None) + 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)), document_object.version, + 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 1dd46bd9..2bd1eeab 100644 --- a/pylsp/workspace.py +++ b/pylsp/workspace.py @@ -176,7 +176,7 @@ 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, doc_version): + def publish_diagnostics(self, doc_uri, diagnostics, doc_version=None): self._endpoint.notify( self.M_PUBLISH_DIAGNOSTICS, params={"uri": doc_uri, "diagnostics": diagnostics, "version": doc_version}, From 9076a6bf0b6674617ecb56065a0c9d8c3764a703 Mon Sep 17 00:00:00 2001 From: Dylan Mayor <36193755+Dylmay@users.noreply.github.com> Date: Tue, 4 Jun 2024 11:39:31 +0100 Subject: [PATCH 3/4] tidier versioning --- pylsp/workspace.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pylsp/workspace.py b/pylsp/workspace.py index 2bd1eeab..f047ed08 100644 --- a/pylsp/workspace.py +++ b/pylsp/workspace.py @@ -177,9 +177,17 @@ def apply_edit(self, edit): return self._endpoint.request(self.M_APPLY_EDIT, {"edit": edit}) 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, "version": doc_version}, + params=params, ) @contextmanager From e582f81fbcc419252affd0c6ed7670a0c0463616 Mon Sep 17 00:00:00 2001 From: Dylan Mayor <36193755+Dylmay@users.noreply.github.com> Date: Sat, 8 Jun 2024 17:26:26 +0100 Subject: [PATCH 4/4] document_object.version --- pylsp/python_lsp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index cee706d2..8606aba1 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -442,7 +442,7 @@ 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, doc_version) + self._lint_text_document(doc_uri, workspace, is_saved, document_object.version) elif isinstance(document_object, Notebook): self._lint_notebook_document(document_object, workspace)