Skip to content

Commit

Permalink
Store diagnostics data in SessionBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Sep 23, 2024
1 parent 3dd85ec commit b2bab2f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,7 @@ def has_capability_async(self, capability_path: str) -> bool:
def shutdown_async(self) -> None:
...

def present_diagnostics_async(
self, is_view_visible: bool, data_per_severity: dict[tuple[int, bool], DiagnosticSeverityData]
) -> None:
def present_diagnostics_async(self, is_view_visible: bool) -> None:
...

def redraw_diagnostics_async(self) -> None:
Expand Down
4 changes: 3 additions & 1 deletion plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def __init__(self, session_view: SessionViewProtocol, buffer_id: int, uri: Docum
self._id = buffer_id
self._pending_changes: PendingChanges | None = None
self.diagnostics: list[tuple[Diagnostic, sublime.Region]] = []
self.diagnostics_data_per_severity: dict[tuple[int, bool], DiagnosticSeverityData] = {}
self.diagnostics_version = -1
self.diagnostics_flags = 0
self._diagnostics_are_visible = False
Expand Down Expand Up @@ -545,13 +546,14 @@ def on_diagnostics_async(
else:
data.regions.append(region)
diagnostics.append((diagnostic, region))
self.diagnostics_data_per_severity = data_per_severity

def present() -> None:
self.diagnostics_version = diagnostics_version
self.diagnostics = diagnostics
self._diagnostics_are_visible = bool(diagnostics)
for sv in self.session_views:
sv.present_diagnostics_async(sv in visible_session_views, data_per_severity)
sv.present_diagnostics_async(sv in visible_session_views)

self._diagnostics_debouncer_async.cancel_pending()
if self._diagnostics_are_visible:
Expand Down
8 changes: 2 additions & 6 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class SessionView:
def __init__(self, listener: AbstractViewListener, session: Session, uri: DocumentUri) -> None:
self._view = listener.view
self._session = session
self._diagnostics_data_per_severity: dict[tuple[int, bool], DiagnosticSeverityData] = {}
self._diagnostic_annotations = DiagnosticsAnnotationsView(self._view, session.config.name)
self._initialize_region_keys()
self._active_requests: dict[int, ActiveRequest] = {}
Expand Down Expand Up @@ -300,10 +299,7 @@ def diagnostics_tag_scope(self, tag: int) -> str | None:
return f'markup.{k.lower()}.lsp'
return None

def present_diagnostics_async(
self, is_view_visible: bool, data_per_severity: dict[tuple[int, bool], DiagnosticSeverityData]
) -> None:
self._diagnostics_data_per_severity = data_per_severity
def present_diagnostics_async(self, is_view_visible: bool) -> None:
self.redraw_diagnostics_async()
listener = self.listener()
if listener:
Expand All @@ -328,7 +324,7 @@ def _draw_diagnostics(
ICON_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO
key = self.diagnostics_key(severity, multiline)
tags = {tag: TagData(f'{key}_tags_{tag}') for tag in DIAGNOSTIC_TAG_VALUES}
data = self._diagnostics_data_per_severity.get((severity, multiline))
data = self._session_buffer.diagnostics_data_per_severity.get((severity, multiline))
if data and severity <= max_severity_level:
non_tag_regions = data.regions
for tag, regions in data.regions_with_tag.items():
Expand Down

0 comments on commit b2bab2f

Please sign in to comment.