Skip to content

Commit

Permalink
maybe I'll get it right eventually
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Sep 11, 2022
1 parent 29bfefc commit 33a0ef0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
3 changes: 0 additions & 3 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,6 @@ def shutdown_async(self) -> None:
def present_diagnostics_async(self) -> None:
...

def update_inline_diagnostics_async(self, diagnostics: List[Diagnostic]) -> None:
...

def on_request_started_async(self, request_id: int, request: Request) -> None:
...

Expand Down
24 changes: 20 additions & 4 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
from .core.typing import Any, Callable, Optional, Dict, Generator, Iterable, List, Tuple, Union
from .core.url import parse_uri
from .core.url import view_to_uri
from .core.views import DIAGNOSTIC_SEVERITY
from .core.views import diagnostic_severity
from .core.views import DOCUMENT_HIGHLIGHT_KIND_SCOPES
from .core.views import DOCUMENT_HIGHLIGHT_KINDS
from .core.views import first_selection_region
from .core.views import format_code_actions_for_quick_panel
from .core.views import format_diagnostics_for_annotation
from .core.views import format_completion
from .core.views import make_command_link
from .core.views import MarkdownLangMap
Expand Down Expand Up @@ -130,6 +132,7 @@ def __repr__(self) -> str:
class DocumentSyncListener(sublime_plugin.ViewEventListener, AbstractViewListener):

ACTIVE_DIAGNOSTIC = "lsp_active_diagnostic"
INLINE_DIAGNOSTIC_REGION_KEY = "lsp_d-annotations"
code_actions_debounce_time = FEATURES_TIMEOUT
color_boxes_debounce_time = FEATURES_TIMEOUT
highlights_debounce_time = FEATURES_TIMEOUT
Expand Down Expand Up @@ -303,13 +306,26 @@ def _update_diagnostic_in_status_bar_async(self) -> None:
self.view.erase_status(self.ACTIVE_DIAGNOSTIC)

def _update_inline_diagnostics_async(self) -> None:
diagnostics = [] # type: List[Diagnostic]
selections_diagnostics = [] # type: List[Diagnostic]
for r in self.view.sel():
session_buffer_diagnostics, _ = self.diagnostics_intersecting_region_async(r)
for _, diagnostics in session_buffer_diagnostics:
diagnostics.extend(diagnostics)
for sv in self.session_views_async():
sv.update_inline_diagnostics_async(diagnostics)
selections_diagnostics.extend(diagnostics)
self.view.erase_regions(self.INLINE_DIAGNOSTIC_REGION_KEY)
if userprefs().show_diagnostics_inline != 'at-cursor':
return
if selections_diagnostics:
sorted_diagnostics = sorted(selections_diagnostics, key=lambda d: d.get('severity', 1))
first_diagnostic = sorted_diagnostics[0]
lsp_range = first_diagnostic.get('range')
if lsp_range:
scope = DIAGNOSTIC_SEVERITY[first_diagnostic.get('severity', 1) - 1][2]
icon = ""
flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
annotation_color = self.view.style_for_scope(scope).get('foreground') or 'red'
regions, annotations = format_diagnostics_for_annotation(sorted_diagnostics, self.view)
self.view.add_regions(
self.INLINE_DIAGNOSTIC_REGION_KEY, regions, scope, icon, flags, annotations, annotation_color)

def session_views_async(self) -> Generator[SessionView, None, None]:
yield from self._session_views.values()
Expand Down
30 changes: 3 additions & 27 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .core.progress import ViewProgressReporter
from .core.promise import Promise
from .core.protocol import CodeLens
from .core.protocol import Diagnostic
from .core.protocol import DiagnosticTag
from .core.protocol import DocumentUri
from .core.protocol import Notification
Expand All @@ -13,7 +12,6 @@
from .core.types import debounced
from .core.typing import Any, Iterable, List, Tuple, Optional, Dict, Generator
from .core.views import DIAGNOSTIC_SEVERITY
from .core.views import format_diagnostics_for_annotation
from .core.views import text_document_identifier
from .session_buffer import SessionBuffer
from weakref import ref
Expand Down Expand Up @@ -84,8 +82,10 @@ def on_before_remove(self) -> None:
self.view.erase_regions(self.diagnostics_key(severity, False))
self.view.erase_regions(self.diagnostics_key(severity, True))
self.view.erase_regions("lsp_document_link")
self._clear_inline_diagnostics_regions()
self.session_buffer.remove_session_view(self)
listener = self.listener()
if listener:
listener.on_diagnostics_updated_async()

@property
def session(self) -> Session:
Expand Down Expand Up @@ -297,30 +297,6 @@ def _draw_diagnostics(self, severity: int, max_severity_level: int, flags: int,
else:
self.view.erase_regions(key)

def update_inline_diagnostics_async(self, diagnostics: List[Diagnostic]) -> None:
region_key = self._inline_diagnostics_region_key()
self.view.erase_regions(region_key)
if userprefs().show_diagnostics_inline != 'at-cursor':
return
if diagnostics:
sorted_diagnostics = sorted(diagnostics, key=lambda d: d.get('severity', 1))
first_diagnostic = sorted_diagnostics[0]
lsp_range = first_diagnostic.get('range')
if lsp_range:
scope = DIAGNOSTIC_SEVERITY[first_diagnostic.get('severity', 1) - 1][2]
icon = ""
flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
annotation_color = self.view.style_for_scope(scope).get('foreground') or 'red'
regions, annotations = format_diagnostics_for_annotation(sorted_diagnostics, self.view)
self.view.add_regions(region_key, regions, scope, icon, flags, annotations, annotation_color)

def _inline_diagnostics_region_key(self) -> str:
return "lsp_d-annotations"

def _clear_inline_diagnostics_regions(self) -> None:
region_key = self._inline_diagnostics_region_key()
self.view.erase_regions(region_key)

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

0 comments on commit 33a0ef0

Please sign in to comment.