[red-knot] Add support for the LSP diagnostic tag (#17657)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Eric Botti 2025-05-03 14:35:03 -04:00 committed by GitHub
parent b51c4f82ea
commit 8535af8516
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 71 additions and 4 deletions

View file

@ -1,6 +1,7 @@
use std::fmt;
use drop_bomb::DebugDropBomb;
use ruff_db::diagnostic::DiagnosticTag;
use ruff_db::{
diagnostic::{Annotation, Diagnostic, DiagnosticId, IntoDiagnosticMessage, Severity, Span},
files::File,
@ -259,6 +260,21 @@ impl LintDiagnosticGuard<'_, '_> {
let ann = self.primary_annotation_mut().unwrap();
ann.set_message(message);
}
/// Adds a tag on the primary annotation for this diagnostic.
///
/// This tag is associated with the primary annotation created
/// for every `Diagnostic` that uses the `LintDiagnosticGuard` API.
/// Specifically, the annotation is derived from the `TextRange` given to
/// the `InferContext::report_lint` API.
///
/// Callers can add additional primary or secondary annotations via the
/// `DerefMut` trait implementation to a `Diagnostic`.
#[expect(dead_code)]
pub(super) fn add_primary_tag(&mut self, tag: DiagnosticTag) {
let ann = self.primary_annotation_mut().unwrap();
ann.push_tag(tag);
}
}
impl std::ops::Deref for LintDiagnosticGuard<'_, '_> {