Skip to content

Commit 80be0a0

Browse files
committed
ruff_db: move ParseDiagnostic to old submodule too
This should have been with the previous two commits, but I missed it.
1 parent b2e90c3 commit 80be0a0

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

crates/red_knot_project/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use metadata::{ProjectDiscoveryError, ProjectMetadata};
99
use red_knot_python_semantic::lint::{LintRegistry, LintRegistryBuilder, RuleSelection};
1010
use red_knot_python_semantic::register_lints;
1111
use red_knot_python_semantic::types::check_types;
12-
use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, ParseDiagnostic, Severity, Span};
12+
use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, OldParseDiagnostic, Severity, Span};
1313
use ruff_db::files::File;
1414
use ruff_db::parsed::parsed_module;
1515
use ruff_db::source::{source_text, SourceTextError};
@@ -414,7 +414,7 @@ fn check_file_impl(db: &dyn Db, file: File) -> Vec<Box<dyn OldDiagnosticTrait>>
414414
let parsed = parsed_module(db.upcast(), file);
415415
diagnostics.extend(parsed.errors().iter().map(|error| {
416416
let diagnostic: Box<dyn OldDiagnosticTrait> =
417-
Box::new(ParseDiagnostic::new(file, error.clone()));
417+
Box::new(OldParseDiagnostic::new(file, error.clone()));
418418
diagnostic
419419
}));
420420

crates/red_knot_test/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use colored::Colorize;
55
use parser as test_parser;
66
use red_knot_python_semantic::types::check_types;
77
use red_knot_python_semantic::{Program, ProgramSettings, PythonPath, SearchPathSettings};
8-
use ruff_db::diagnostic::{DisplayDiagnosticConfig, OldDiagnosticTrait, ParseDiagnostic};
8+
use ruff_db::diagnostic::{DisplayDiagnosticConfig, OldDiagnosticTrait, OldParseDiagnostic};
99
use ruff_db::files::{system_path_to_file, File, Files};
1010
use ruff_db::panic::catch_unwind;
1111
use ruff_db::parsed::parsed_module;
@@ -201,7 +201,7 @@ fn run_test(
201201
.cloned()
202202
.map(|error| {
203203
let diagnostic: Box<dyn OldDiagnosticTrait> =
204-
Box::new(ParseDiagnostic::new(test_file.file, error));
204+
Box::new(OldParseDiagnostic::new(test_file.file, error));
205205
diagnostic
206206
})
207207
.collect();

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
use std::borrow::Cow;
21
use std::fmt::Formatter;
32

43
use thiserror::Error;
54

65
use ruff_annotate_snippets::Level as AnnotateLevel;
7-
use ruff_python_parser::ParseError;
86
use ruff_text_size::TextRange;
97

108
pub use crate::diagnostic::old::{
11-
OldDiagnosticTrait, OldDisplayDiagnostic, OldSecondaryDiagnosticMessage,
9+
OldDiagnosticTrait, OldDisplayDiagnostic, OldParseDiagnostic, OldSecondaryDiagnosticMessage,
1210
};
1311
use crate::files::File;
1412

@@ -245,33 +243,3 @@ impl DisplayDiagnosticConfig {
245243
DisplayDiagnosticConfig { color: yes }
246244
}
247245
}
248-
249-
#[derive(Debug)]
250-
pub struct OldParseDiagnostic {
251-
file: File,
252-
error: ParseError,
253-
}
254-
255-
impl OldParseDiagnostic {
256-
pub fn new(file: File, error: ParseError) -> Self {
257-
Self { file, error }
258-
}
259-
}
260-
261-
impl OldDiagnosticTrait for OldParseDiagnostic {
262-
fn id(&self) -> DiagnosticId {
263-
DiagnosticId::InvalidSyntax
264-
}
265-
266-
fn message(&self) -> Cow<str> {
267-
self.error.error.to_string().into()
268-
}
269-
270-
fn span(&self) -> Option<Span> {
271-
Some(Span::from(self.file).with_range(self.error.location))
272-
}
273-
274-
fn severity(&self) -> Severity {
275-
Severity::Error
276-
}
277-
}

crates/ruff_db/src/diagnostic/old.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use ruff_annotate_snippets::{
44
Annotation as AnnotateAnnotation, Level as AnnotateLevel, Message as AnnotateMessage,
55
Renderer as AnnotateRenderer, Snippet as AnnotateSnippet,
66
};
7+
use ruff_python_parser::ParseError;
78
use ruff_source_file::{OneIndexed, SourceCode};
89
use ruff_text_size::TextRange;
910

1011
use crate::{
1112
diagnostic::{DiagnosticId, DisplayDiagnosticConfig, Severity, Span},
13+
files::File,
1214
source::{line_index, source_text},
1315
Db,
1416
};
@@ -342,3 +344,33 @@ impl OldDiagnosticTrait for std::sync::Arc<dyn OldDiagnosticTrait> {
342344
(**self).severity()
343345
}
344346
}
347+
348+
#[derive(Debug)]
349+
pub struct OldParseDiagnostic {
350+
file: File,
351+
error: ParseError,
352+
}
353+
354+
impl OldParseDiagnostic {
355+
pub fn new(file: File, error: ParseError) -> Self {
356+
Self { file, error }
357+
}
358+
}
359+
360+
impl OldDiagnosticTrait for OldParseDiagnostic {
361+
fn id(&self) -> DiagnosticId {
362+
DiagnosticId::InvalidSyntax
363+
}
364+
365+
fn message(&self) -> Cow<str> {
366+
self.error.error.to_string().into()
367+
}
368+
369+
fn span(&self) -> Option<Span> {
370+
Some(Span::from(self.file).with_range(self.error.location))
371+
}
372+
373+
fn severity(&self) -> Severity {
374+
Severity::Error
375+
}
376+
}

0 commit comments

Comments
 (0)