Skip to content
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
26 changes: 17 additions & 9 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2059,16 +2059,16 @@ def _on_workspace_diagnostics_async(
) -> None:
if reset_pending_response:
self.workspace_diagnostics_pending_responses[identifier] = None
for diagnostic_report in response['items']:
uri = normalize_uri(diagnostic_report['uri'])
version = diagnostic_report['version']
for report in response['items']:
uri = normalize_uri(report['uri'])
version = report['version']
# Skip if outdated
if isinstance(version, int) and (session_buffer := self.get_session_buffer_for_uri_async(uri)) and \
version < session_buffer.last_synced_version:
continue
self.diagnostics_result_ids[(uri, identifier)] = diagnostic_report.get('resultId')
if is_workspace_full_document_diagnostic_report(diagnostic_report):
self.handle_diagnostics_async(uri, identifier, version, diagnostic_report['items'])
self.diagnostics_result_ids[(uri, identifier)] = report.get('resultId')
diagnostics = report['items'] if is_workspace_full_document_diagnostic_report(report) else None
self.handle_diagnostics_async(uri, identifier, version, diagnostics)

def _on_workspace_diagnostics_error_async(self, identifier: DiagnosticsIdentifier, error: ResponseError) -> None:
if error['code'] == LSPErrorCodes.ServerCancelled:
Expand Down Expand Up @@ -2209,7 +2209,11 @@ def on_text_document_publish_diagnostics(self, params: PublishDiagnosticsParams)
self.handle_diagnostics_async(params['uri'], None, None, params['diagnostics'])

def handle_diagnostics_async(
self, uri: DocumentUri, identifier: DiagnosticsIdentifier, version: int | None, diagnostics: list[Diagnostic]
self,
uri: DocumentUri,
identifier: DiagnosticsIdentifier,
version: int | None,
diagnostics: list[Diagnostic] | None
) -> None:
mgr = self.manager()
if not mgr:
Expand All @@ -2218,8 +2222,12 @@ def handle_diagnostics_async(
if isinstance(reason, str):
debug("ignoring unsuitable diagnostics for", uri, "reason:", reason)
return
self.diagnostics.set_diagnostics(uri, identifier, diagnostics)
mgr.on_diagnostics_updated()
if diagnostics is not None:
self.diagnostics.set_diagnostics(uri, identifier, diagnostics)
mgr.on_diagnostics_updated()
Comment thread
rchl marked this conversation as resolved.
# Even if we received an UnchangedDocumentDiagnosticReport (represented by the diagnostics argument being None)
# we still have to redraw the diagnostic regions in the view to ensure they keep their original positions after
# a buffer change.
if session_buffer := self.get_session_buffer_for_uri_async(uri):
self._publish_diagnostics_to_session_buffer_async(
session_buffer, self.diagnostics.get_diagnostics_for_uri(uri), version)
Expand Down
12 changes: 6 additions & 6 deletions plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,14 +671,14 @@ def _on_document_diagnostic_async(
self._diagnostics_versions[identifier] = version
self._document_diagnostic_pending_requests[identifier] = None
self.session.diagnostics_result_ids[(self._last_known_uri, identifier)] = response.get('resultId')
if is_related_full_document_diagnostic_report(response):
self.session.handle_diagnostics_async(self._last_known_uri, identifier, version, response['items'])
diagnostics = response['items'] if is_related_full_document_diagnostic_report(response) else None
self.session.handle_diagnostics_async(self._last_known_uri, identifier, version, diagnostics)
if related_documents := response.get('relatedDocuments'):
for uri, diagnostic_report in related_documents.items():
for uri, report in related_documents.items():
uri = normalize_uri(uri)
self.session.diagnostics_result_ids[(uri, identifier)] = diagnostic_report.get('resultId')
if is_full_document_diagnostic_report(diagnostic_report):
self.session.handle_diagnostics_async(uri, identifier, None, diagnostic_report['items'])
self.session.diagnostics_result_ids[(uri, identifier)] = report.get('resultId')
diagnostics = report['items'] if is_full_document_diagnostic_report(report) else None
self.session.handle_diagnostics_async(uri, identifier, None, diagnostics)

def _on_document_diagnostic_error_async(
self, view: sublime.View, identifier: DiagnosticsIdentifier, version: int, error: ResponseError
Expand Down