Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version support to workspace/publishDiagnostics #565

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading