Implement Ranged on more structs (#6921)

Now that it's in `ruff_text_size`, we can use it in a few places that we
couldn't before.
This commit is contained in:
Charlie Marsh 2023-08-27 15:03:08 -04:00 committed by GitHub
parent fc89976c24
commit 059757a8c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 104 additions and 115 deletions

View file

@ -15,7 +15,7 @@ pub use junit::JunitEmitter;
pub use pylint::PylintEmitter;
use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix};
use ruff_source_file::{SourceFile, SourceLocation};
use ruff_text_size::{TextRange, TextSize};
use ruff_text_size::{Ranged, TextRange, TextSize};
pub use text::TextEmitter;
use crate::jupyter::Notebook;
@ -66,14 +66,6 @@ impl Message {
pub fn compute_end_location(&self) -> SourceLocation {
self.file.to_source_code().source_location(self.end())
}
pub const fn start(&self) -> TextSize {
self.range.start()
}
pub const fn end(&self) -> TextSize {
self.range.end()
}
}
impl Ord for Message {
@ -88,6 +80,12 @@ impl PartialOrd for Message {
}
}
impl Ranged for Message {
fn range(&self) -> TextRange {
self.range
}
}
struct MessageWithLocation<'a> {
message: &'a Message,
start_location: SourceLocation,
@ -154,7 +152,7 @@ mod tests {
use ruff_diagnostics::{Diagnostic, DiagnosticKind, Edit, Fix};
use ruff_source_file::SourceFileBuilder;
use ruff_text_size::{TextRange, TextSize};
use ruff_text_size::{Ranged, TextRange, TextSize};
use crate::message::{Emitter, EmitterContext, Message};