ruff_db: move ParseDiagnostic to old submodule too

This should have been with the previous two commits, but I missed it.
This commit is contained in:
Andrew Gallant 2025-03-03 08:32:56 -05:00 committed by Andrew Gallant
parent b2e90c3f5c
commit 80be0a0115
4 changed files with 37 additions and 37 deletions

View file

@ -9,7 +9,7 @@ pub use metadata::{ProjectDiscoveryError, ProjectMetadata};
use red_knot_python_semantic::lint::{LintRegistry, LintRegistryBuilder, RuleSelection};
use red_knot_python_semantic::register_lints;
use red_knot_python_semantic::types::check_types;
use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, ParseDiagnostic, Severity, Span};
use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, OldParseDiagnostic, Severity, Span};
use ruff_db::files::File;
use ruff_db::parsed::parsed_module;
use ruff_db::source::{source_text, SourceTextError};
@ -414,7 +414,7 @@ fn check_file_impl(db: &dyn Db, file: File) -> Vec<Box<dyn OldDiagnosticTrait>>
let parsed = parsed_module(db.upcast(), file);
diagnostics.extend(parsed.errors().iter().map(|error| {
let diagnostic: Box<dyn OldDiagnosticTrait> =
Box::new(ParseDiagnostic::new(file, error.clone()));
Box::new(OldParseDiagnostic::new(file, error.clone()));
diagnostic
}));

View file

@ -5,7 +5,7 @@ use colored::Colorize;
use parser as test_parser;
use red_knot_python_semantic::types::check_types;
use red_knot_python_semantic::{Program, ProgramSettings, PythonPath, SearchPathSettings};
use ruff_db::diagnostic::{DisplayDiagnosticConfig, OldDiagnosticTrait, ParseDiagnostic};
use ruff_db::diagnostic::{DisplayDiagnosticConfig, OldDiagnosticTrait, OldParseDiagnostic};
use ruff_db::files::{system_path_to_file, File, Files};
use ruff_db::panic::catch_unwind;
use ruff_db::parsed::parsed_module;
@ -201,7 +201,7 @@ fn run_test(
.cloned()
.map(|error| {
let diagnostic: Box<dyn OldDiagnosticTrait> =
Box::new(ParseDiagnostic::new(test_file.file, error));
Box::new(OldParseDiagnostic::new(test_file.file, error));
diagnostic
})
.collect();

View file

@ -1,14 +1,12 @@
use std::borrow::Cow;
use std::fmt::Formatter;
use thiserror::Error;
use ruff_annotate_snippets::Level as AnnotateLevel;
use ruff_python_parser::ParseError;
use ruff_text_size::TextRange;
pub use crate::diagnostic::old::{
OldDiagnosticTrait, OldDisplayDiagnostic, OldSecondaryDiagnosticMessage,
OldDiagnosticTrait, OldDisplayDiagnostic, OldParseDiagnostic, OldSecondaryDiagnosticMessage,
};
use crate::files::File;
@ -245,33 +243,3 @@ impl DisplayDiagnosticConfig {
DisplayDiagnosticConfig { color: yes }
}
}
#[derive(Debug)]
pub struct OldParseDiagnostic {
file: File,
error: ParseError,
}
impl OldParseDiagnostic {
pub fn new(file: File, error: ParseError) -> Self {
Self { file, error }
}
}
impl OldDiagnosticTrait for OldParseDiagnostic {
fn id(&self) -> DiagnosticId {
DiagnosticId::InvalidSyntax
}
fn message(&self) -> Cow<str> {
self.error.error.to_string().into()
}
fn span(&self) -> Option<Span> {
Some(Span::from(self.file).with_range(self.error.location))
}
fn severity(&self) -> Severity {
Severity::Error
}
}

View file

@ -4,11 +4,13 @@ use ruff_annotate_snippets::{
Annotation as AnnotateAnnotation, Level as AnnotateLevel, Message as AnnotateMessage,
Renderer as AnnotateRenderer, Snippet as AnnotateSnippet,
};
use ruff_python_parser::ParseError;
use ruff_source_file::{OneIndexed, SourceCode};
use ruff_text_size::TextRange;
use crate::{
diagnostic::{DiagnosticId, DisplayDiagnosticConfig, Severity, Span},
files::File,
source::{line_index, source_text},
Db,
};
@ -342,3 +344,33 @@ impl OldDiagnosticTrait for std::sync::Arc<dyn OldDiagnosticTrait> {
(**self).severity()
}
}
#[derive(Debug)]
pub struct OldParseDiagnostic {
file: File,
error: ParseError,
}
impl OldParseDiagnostic {
pub fn new(file: File, error: ParseError) -> Self {
Self { file, error }
}
}
impl OldDiagnosticTrait for OldParseDiagnostic {
fn id(&self) -> DiagnosticId {
DiagnosticId::InvalidSyntax
}
fn message(&self) -> Cow<str> {
self.error.error.to_string().into()
}
fn span(&self) -> Option<Span> {
Some(Span::from(self.file).with_range(self.error.location))
}
fn severity(&self) -> Severity {
Severity::Error
}
}