Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions annotations.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
margin: 0;
border-width: 0;
}
.lsp_annotation .errors {
.lsp_annotation .error {
color: color(var(--redish) alpha(0.85));
}
.lsp_annotation .warnings {
.lsp_annotation .warning {
color: color(var(--yellowish) alpha(0.85));
}
.lsp_annotation .info {
.lsp_annotation .information {
color: color(var(--bluish) alpha(0.85));
}
.lsp_annotation .hints {
.lsp_annotation .hint {
color: color(var(--bluish) alpha(0.85));
}
2 changes: 1 addition & 1 deletion plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def diagnostics_highlight_style_flags(self) -> list[sublime.RegionFlags | None]:
flags.append(self._style_str_to_flag(user_style))
return flags
else:
# Defaults are defined in DIAGNOSTIC_SEVERITY in plugin/core/views.py
# Defaults are defined in DIAGNOSTIC_STYLES in plugin/core/views.py
return [None] * 4 # default styling


Expand Down
85 changes: 64 additions & 21 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from .types import ClientConfig
from .url import parse_uri
from .workspace import is_subpath_of
from dataclasses import dataclass
from typing import Any
from typing import Callable
from typing import cast
Expand All @@ -76,34 +77,78 @@
_baseflags = sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_EMPTY_AS_OVERWRITE | sublime.RegionFlags.NO_UNDO # noqa: E501
_multilineflags = sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.NO_UNDO

DIAGNOSTIC_SEVERITY: list[tuple[str, str, str, str, sublime.RegionFlags, sublime.RegionFlags]] = [
# Kind CSS class Scope for color Icon resource add_regions flags for single-line diagnostic multi-line diagnostic # noqa: E501
("error", "errors", "region.redish markup.error.lsp", "Packages/LSP/icons/error.png", _baseflags | sublime.RegionFlags.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501
("warning", "warnings", "region.yellowish markup.warning.lsp", "Packages/LSP/icons/warning.png", _baseflags | sublime.RegionFlags.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501
("info", "info", "region.bluish markup.info.lsp", "Packages/LSP/icons/info.png", _baseflags | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE, _multilineflags), # noqa: E501
("hint", "hints", "region.bluish markup.info.hint.lsp", "", _baseflags | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE, _multilineflags), # noqa: E501
]

@dataclass
class DiagnosticStyle:
kind: str
css_class: str
region_scope: str
icon_resource: str
single_line_region_flags: sublime.RegionFlags
multi_line_region_flags: sublime.RegionFlags


DIAGNOSTIC_STYLES: dict[DiagnosticSeverity, DiagnosticStyle] = {
DiagnosticSeverity.Error: DiagnosticStyle(
'error',
'error',
'region.redish markup.error.lsp',
'Packages/LSP/icons/error.png',
_baseflags | sublime.RegionFlags.DRAW_SQUIGGLY_UNDERLINE,
_multilineflags
),
DiagnosticSeverity.Warning: DiagnosticStyle(
'warning',
'warning',
'region.yellowish markup.warning.lsp',
'Packages/LSP/icons/warning.png',
_baseflags | sublime.RegionFlags.DRAW_SQUIGGLY_UNDERLINE,
_multilineflags
),
DiagnosticSeverity.Information: DiagnosticStyle(
'info',
'information',
'region.bluish markup.info.lsp',
'Packages/LSP/icons/info.png',
_baseflags | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE,
_multilineflags
),
DiagnosticSeverity.Hint: DiagnosticStyle(
'hint',
'hint',
'region.bluish markup.info.hint.lsp',
'',
_baseflags | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE,
_multilineflags
),
}


class DiagnosticSeverityData:

__slots__ = ('regions', 'regions_with_tag', 'annotations', 'scope', 'icon')
__slots__ = ('severity', 'regions', 'regions_with_tag', 'annotations')

def __init__(self, severity: int) -> None:
def __init__(self, severity: DiagnosticSeverity) -> None:
self.severity = severity
self.regions: list[sublime.Region] = []
self.regions_with_tag: dict[DiagnosticTag, list[sublime.Region]] = {}
self.annotations: list[str] = []
_, _, self.scope, self.icon, _, _ = DIAGNOSTIC_SEVERITY[severity - 1]
if userprefs().diagnostics_gutter_marker != "sign":
self.icon = "" if severity == DiagnosticSeverity.Hint else userprefs().diagnostics_gutter_marker

@property
def scope(self) -> str:
return DIAGNOSTIC_STYLES[self.severity].region_scope

@property
def icon(self) -> str:
if userprefs().diagnostics_gutter_marker == "sign":
return DIAGNOSTIC_STYLES[self.severity].icon_resource
else:
return "" if self.severity == DiagnosticSeverity.Hint else userprefs().diagnostics_gutter_marker
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we really need to expose those on DiagnosticSeverityData.

Or at least scope we could easily read from DIAGNOSTIC_STYLES.

icon needs to be re-evaluated currently so it needs to exist somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



class InvalidUriSchemeException(Exception):
def __init__(self, uri: str) -> None:
self.uri = uri

def __str__(self) -> str:
return f"invalid URI scheme: {self.uri}"
super().__init__(f"invalid URI scheme: {uri}")
Comment on lines 137 to +139
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by change. Was unnecessarily complicated.



def get_line(window: sublime.Window, file_name: str, row: int, strip: bool = True) -> str:
Expand Down Expand Up @@ -698,10 +743,8 @@ def document_color_params(view: sublime.View) -> DocumentColorParams:
return {"textDocument": text_document_identifier(view)}


def format_severity(severity: int) -> str:
if 1 <= severity <= len(DIAGNOSTIC_SEVERITY):
return DIAGNOSTIC_SEVERITY[severity - 1][0]
return "???"
def format_severity(severity: DiagnosticSeverity) -> str:
return DIAGNOSTIC_STYLES[severity].kind if severity in DIAGNOSTIC_STYLES else "???"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If severity is typed as DiagnosticSeverity, then we shouldn't need the in check.
I think this is pretty old code with the "???" and that fallback should actually be unnecessary anyway.

Also this function seems to be used only in a single place a few lines below, so you could just inline that below as

DIAGNOSTIC_STYLES[diagnostic_severity(diagnostic)].kind



def diagnostic_severity(diagnostic: Diagnostic) -> DiagnosticSeverity:
Expand Down Expand Up @@ -851,7 +894,7 @@ def format_diagnostic_for_html(config: ClientConfig, diagnostic: Diagnostic, bas
if related_infos := diagnostic.get("relatedInformation"):
info = "<br>".join(_format_diagnostic_related_info(config, info, base_dir) for info in related_infos)
html += '<br>' + _html_element("pre", info, class_name="related_info", escape=False)
severity_class = DIAGNOSTIC_SEVERITY[diagnostic_severity(diagnostic) - 1][1]
severity_class = DIAGNOSTIC_STYLES[diagnostic_severity(diagnostic)].kind
return _html_element("pre", html, class_name=severity_class, escape=False)


Expand Down
4 changes: 2 additions & 2 deletions plugin/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from .core.settings import userprefs
from .core.types import DocumentSelector_
from .core.url import normalize_uri
from .core.views import DIAGNOSTIC_SEVERITY
from .core.views import diagnostic_severity
from .core.views import DIAGNOSTIC_STYLES
from .core.views import format_diagnostics_for_annotation
from typing import Union
import itertools
Expand Down Expand Up @@ -141,7 +141,7 @@ def draw(self, diagnostics: list[tuple[Diagnostic, sublime.Region]]) -> None:
continue
matching_diagnostics[0].append(diagnostic)
matching_diagnostics[1].append(region)
css_class = DIAGNOSTIC_SEVERITY[severity - 1][1]
css_class = DIAGNOSTIC_STYLES[severity].css_class
annotations = format_diagnostics_for_annotation(matching_diagnostics[0], css_class)
color = self._severity_colors[severity]
self._view.add_regions(
Expand Down
11 changes: 6 additions & 5 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .core.sessions import Session
from .core.settings import userprefs
from .core.views import ChangeEventAction
from .core.views import DIAGNOSTIC_SEVERITY
from .core.views import DIAGNOSTIC_STYLES
from .core.views import document_highlight_key
from .core.views import make_command_link
from .core.views import range_to_region
Expand Down Expand Up @@ -94,7 +94,7 @@ def on_before_remove(self) -> None:
self.session.cancel_request_async(request_id)
self.session.unregister_session_view_async(self)
self.session.config.erase_view_status(self.view)
for severity in reversed(range(1, len(DIAGNOSTIC_SEVERITY) + 1)):
for severity in reversed(DIAGNOSTIC_STYLES.keys()):
self.view.erase_regions(f"{self.diagnostics_key(severity, False)}_icon")
self.view.erase_regions(f"{self.diagnostics_key(severity, False)}_underline")
self.view.erase_regions(f"{self.diagnostics_key(severity, True)}_icon")
Expand Down Expand Up @@ -306,9 +306,10 @@ def _redraw_diagnostics_async(self) -> None:
flags = userprefs().diagnostics_highlight_style_flags() # for single lines
multiline_flags = None if userprefs().show_multiline_diagnostics_highlights else sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.NO_UNDO # noqa: E501
level = userprefs().show_diagnostics_severity_level
for sev in reversed(range(1, len(DIAGNOSTIC_SEVERITY) + 1)):
self._draw_diagnostics(sev, level, flags[sev - 1] or DIAGNOSTIC_SEVERITY[sev - 1][4], multiline=False)
self._draw_diagnostics(sev, level, multiline_flags or DIAGNOSTIC_SEVERITY[sev - 1][5], multiline=True)
for sev in reversed(DIAGNOSTIC_STYLES.keys()):
style = DIAGNOSTIC_STYLES[sev]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified:

Suggested change
for sev in reversed(DIAGNOSTIC_STYLES.keys()):
style = DIAGNOSTIC_STYLES[sev]
for sev, style in reversed(DIAGNOSTIC_STYLES.items()):

self._draw_diagnostics(sev, level, flags[sev - 1] or style.single_line_region_flags, multiline=False)
self._draw_diagnostics(sev, level, multiline_flags or style.multi_line_region_flags, multiline=True)
self._diagnostic_annotations.draw(self.session_buffer.diagnostics)

def _draw_diagnostics(
Expand Down
25 changes: 10 additions & 15 deletions popups.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,25 @@
margin-bottom: 0.5rem;
font-family: var(--mdpopups-font-mono);
}
.errors {
.error,
.warning,
.information,
.hint {
border-width: 0;
background-color: color(var(--redish) alpha(0.25));
color: var(--foreground);
padding: 0.5rem;
white-space: pre-wrap;
}
.warnings {
border-width: 0;
.error {
background-color: color(var(--redish) alpha(0.25));
}
.warning {
background-color: color(var(--yellowish) alpha(0.25));
color: var(--foreground);
padding: 0.5rem;
}
.info {
border-width: 0;
.information {
background-color: color(var(--bluish) alpha(0.25));
color: var(--foreground);
padding: 0.5rem;
}
.hints {
border-width: 0;
.hint {
background-color: color(var(--bluish) alpha(0.25));
color: var(--foreground);
padding: 0.5rem;
}
.actions, .code-actions {
font-family: system;
Expand Down