-
Notifications
You must be signed in to change notification settings - Fork 191
Refactor diagnostic css classes #2809
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
Changes from 1 commit
31f9373
46102ce
d3c202e
ab2ad81
33ad735
9c9974a
f068003
c33baae
7cdd2ae
ea424a4
13ca933
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
|
|
||
| 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
@@ -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 "???" | ||
|
||
|
|
||
|
|
||
| def diagnostic_severity(diagnostic: Diagnostic) -> DiagnosticSeverity: | ||
|
|
@@ -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) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||
|
|
@@ -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") | ||||||||
|
|
@@ -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] | ||||||||
|
||||||||
| for sev in reversed(DIAGNOSTIC_STYLES.keys()): | |
| style = DIAGNOSTIC_STYLES[sev] | |
| for sev, style in reversed(DIAGNOSTIC_STYLES.items()): |
There was a problem hiding this comment.
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
scopewe could easily read fromDIAGNOSTIC_STYLES.iconneeds to be re-evaluated currently so it needs to exist somewhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ab2ad81 and 9c9974a