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

Fix tagged diagnostics flickering on document changes #2274

Merged
merged 1 commit into from
May 18, 2023
Merged
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
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