red_knot: use Diagnostic inside of red knot

This replaces things like `TypeCheckDiagnostic` with the new Diagnostic`
type.

This is a "surgical" replacement where we retain the existing API of
of diagnostic reporting such that _most_ of Red Knot doesn't need to be
changed to support this update. But it will enable us to start using the
new diagnostic renderer and to delete the old renderer. It also paves
the path for exposing the new `Diagnostic` data model to the broader Red
Knot codebase.
This commit is contained in:
Andrew Gallant 2025-03-21 14:01:34 -04:00 committed by Andrew Gallant
parent 883b8e3870
commit 4e169e5f6c
18 changed files with 263 additions and 339 deletions

View file

@ -1,7 +1,7 @@
use crate::lint::{GetLintError, Level, LintMetadata, LintRegistry, LintStatus};
use crate::types::{TypeCheckDiagnostic, TypeCheckDiagnostics};
use crate::types::TypeCheckDiagnostics;
use crate::{declare_lint, lint::LintId, Db};
use ruff_db::diagnostic::DiagnosticId;
use ruff_db::diagnostic::{Annotation, Diagnostic, DiagnosticId, Span};
use ruff_db::{files::File, parsed::parsed_module, source::source_text};
use ruff_python_parser::TokenKind;
use ruff_python_trivia::Cursor;
@ -319,14 +319,11 @@ impl<'a> CheckSuppressionsContext<'a> {
return;
};
self.diagnostics.push(TypeCheckDiagnostic {
id: DiagnosticId::Lint(lint.name()),
message: message.to_string(),
range,
severity,
file: self.file,
secondary_messages: vec![],
});
let id = DiagnosticId::Lint(lint.name());
let mut diag = Diagnostic::new(id, severity, "");
let span = Span::from(self.file).with_range(range);
diag.annotate(Annotation::primary(span).message(message));
self.diagnostics.push(diag);
}
}