From 80be0a0115c84bec3eb34116550e72766915a30c Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 3 Mar 2025 08:32:56 -0500 Subject: [PATCH] ruff_db: move `ParseDiagnostic` to `old` submodule too This should have been with the previous two commits, but I missed it. --- crates/red_knot_project/src/lib.rs | 4 ++-- crates/red_knot_test/src/lib.rs | 4 ++-- crates/ruff_db/src/diagnostic/mod.rs | 34 +--------------------------- crates/ruff_db/src/diagnostic/old.rs | 32 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/crates/red_knot_project/src/lib.rs b/crates/red_knot_project/src/lib.rs index 161030d5b0..1cc4c7d850 100644 --- a/crates/red_knot_project/src/lib.rs +++ b/crates/red_knot_project/src/lib.rs @@ -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> let parsed = parsed_module(db.upcast(), file); diagnostics.extend(parsed.errors().iter().map(|error| { let diagnostic: Box = - Box::new(ParseDiagnostic::new(file, error.clone())); + Box::new(OldParseDiagnostic::new(file, error.clone())); diagnostic })); diff --git a/crates/red_knot_test/src/lib.rs b/crates/red_knot_test/src/lib.rs index 04fbf2faf8..bafc8e65fe 100644 --- a/crates/red_knot_test/src/lib.rs +++ b/crates/red_knot_test/src/lib.rs @@ -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 = - Box::new(ParseDiagnostic::new(test_file.file, error)); + Box::new(OldParseDiagnostic::new(test_file.file, error)); diagnostic }) .collect(); diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index ce28064835..d6f6801f77 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -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 { - self.error.error.to_string().into() - } - - fn span(&self) -> Option { - Some(Span::from(self.file).with_range(self.error.location)) - } - - fn severity(&self) -> Severity { - Severity::Error - } -} diff --git a/crates/ruff_db/src/diagnostic/old.rs b/crates/ruff_db/src/diagnostic/old.rs index 02ce62e62a..1486269617 100644 --- a/crates/ruff_db/src/diagnostic/old.rs +++ b/crates/ruff_db/src/diagnostic/old.rs @@ -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 { (**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 { + self.error.error.to_string().into() + } + + fn span(&self) -> Option { + Some(Span::from(self.file).with_range(self.error.location)) + } + + fn severity(&self) -> Severity { + Severity::Error + } +}