Skip to content

Commit

Permalink
Fix tagged diagnostics flickering on document changes (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored May 18, 2023
1 parent fb623c4 commit a6edba3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
import functools
import sublime

DIAGNOSTIC_TAG_VALUES = [v for (k, v) in DiagnosticTag.__dict__.items() if not k.startswith('_')]
DIAGNOSTIC_TAG_VALUES = [v for (k, v) in DiagnosticTag.__dict__.items() if not k.startswith('_')] # type: List[int]
HOVER_HIGHLIGHT_KEY = "lsp_hover_highlight"


class TagData:
__slots__ = ('key', 'regions', 'scope')

def __init__(self, key: str, regions: List[sublime.Region] = [], scope: str = '') -> None:
self.key = key
self.regions = regions
self.scope = scope


class SessionView:
"""
Holds state per session per view.
Expand Down Expand Up @@ -286,24 +295,28 @@ def present_diagnostics_async(self, is_view_visible: bool) -> None:
def _draw_diagnostics(self, severity: int, max_severity_level: int, flags: int, multiline: bool) -> None:
ICON_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
key = self.diagnostics_key(severity, multiline)
key_tags = {tag: '{}_tags_{}'.format(key, tag) for tag in DIAGNOSTIC_TAG_VALUES}
for key_tag in key_tags.values():
self.view.erase_regions(key_tag)
tags = {tag: TagData('{}_tags_{}'.format(key, tag)) for tag in DIAGNOSTIC_TAG_VALUES}
data = self.session_buffer.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():
tag_scope = self.diagnostics_tag_scope(tag)
# Trick to only add tag regions if there is a corresponding color scheme scope defined.
if tag_scope and 'background' in self.view.style_for_scope(tag_scope):
self.view.add_regions(key_tags[tag], regions, tag_scope, flags=sublime.DRAW_NO_OUTLINE)
tags[tag].regions = regions
tags[tag].scope = tag_scope
else:
non_tag_regions.extend(regions)
self.view.add_regions("{}_icon".format(key), non_tag_regions, data.scope, data.icon, ICON_FLAGS)
self.view.add_regions("{}_underline".format(key), non_tag_regions, data.scope, "", flags)
else:
self.view.erase_regions("{}_icon".format(key))
self.view.erase_regions("{}_underline".format(key))
for data in tags.values():
if data.regions:
self.view.add_regions(data.key, data.regions, data.scope, flags=sublime.DRAW_NO_OUTLINE)
else:
self.view.erase_regions(data.key)

def on_request_started_async(self, request_id: int, request: Request) -> None:
self._active_requests[request_id] = ActiveRequest(self, request_id, request)
Expand Down

0 comments on commit a6edba3

Please sign in to comment.