From 1cdd0fa7e30b96612f47344a70a73457018eb1b2 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 24 Jul 2024 16:33:48 -0400 Subject: [PATCH] feat: add range_description and info to diagnostic (#1298) --- src/context.rs | 2 ++ src/diagnostic.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index 98569d48..17c8f5ed 100644 --- a/src/context.rs +++ b/src/context.rs @@ -442,6 +442,8 @@ impl<'a> Context<'a> { hint: maybe_hint, fixes, custom_docs_url: None, + range_description: None, + info: vec![], } } } diff --git a/src/diagnostic.rs b/src/diagnostic.rs index 93173c74..f664b2e1 100644 --- a/src/diagnostic.rs +++ b/src/diagnostic.rs @@ -44,6 +44,10 @@ pub struct LintDiagnostic { /// URL to the lint rule documentation. By default, the url uses the /// code to link to lint.deno.land pub custom_docs_url: Option, + /// Additional information displayed beside the highlighted range. + pub range_description: Option, + /// Displays additional information at the end of a diagnostic. + pub info: Vec>, } impl Diagnostic for LintDiagnostic { @@ -77,7 +81,7 @@ impl Diagnostic for LintDiagnostic { highlights: vec![DiagnosticSnippetHighlight { range, style: DiagnosticSnippetHighlightStyle::Error, - description: None, + description: self.range_description.as_deref().map(Cow::Borrowed), }], }) } @@ -91,7 +95,7 @@ impl Diagnostic for LintDiagnostic { } fn info(&self) -> Cow<'_, [std::borrow::Cow<'_, str>]> { - Cow::Borrowed(&[]) + Cow::Borrowed(&self.info) } fn docs_url(&self) -> Option> {