Skip to content

Commit

Permalink
Add version support to workspace/publishDiagnostics (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylmay authored Jul 24, 2024
1 parent cf3cea1 commit 9b79576
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pylsp/python_lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 10 additions & 2 deletions pylsp/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b79576

Please sign in to comment.