Skip to content

Refactor diagnostic css classes#2809

Merged
rchl merged 11 commits intomainfrom
refactor/diagnostic-class
Mar 16, 2026
Merged

Refactor diagnostic css classes#2809
rchl merged 11 commits intomainfrom
refactor/diagnostic-class

Conversation

@rchl
Copy link
Member

@rchl rchl commented Mar 16, 2026

Address #2788 (comment). I don't want to make that other PR too busy so making this change separately.

  • Change names of diagnostics CSS classes for consistency.
  • Replace DIAGNOSTIC_SEVERITY (list of tuples) with DIAGNOSTIC_STYLES (dict keyed by DiagnosticSeverity). Accessing properties by index was not very readable and same for having to subtract 1 from severity when indexing DIAGNOSTIC_SEVERITY.

Comment on lines 149 to +151
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}")
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.

Comment on lines +137 to +146
@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.

Comment on lines +310 to +311
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()):

Comment on lines +746 to +747
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

@rchl rchl merged commit 190640a into main Mar 16, 2026
8 checks passed
@rchl rchl deleted the refactor/diagnostic-class branch March 16, 2026 21:26
@rchl rchl mentioned this pull request Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants