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

@ -3,7 +3,7 @@ use std::cmp::Ordering;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use ruff_text_size::{TextRange, TextSize};
use ruff_text_size::{Ranged, TextRange, TextSize};
/// A text edit to be applied to a source file. Inserts, deletes, or replaces
/// content at a given location.
@ -62,20 +62,6 @@ impl Edit {
self.content.as_deref()
}
/// Returns the start location of the edit in the source document.
pub const fn start(&self) -> TextSize {
self.range.start()
}
pub const fn range(&self) -> TextRange {
self.range
}
/// Returns the edit's end location in the source document.
pub const fn end(&self) -> TextSize {
self.range.end()
}
fn kind(&self) -> EditOperationKind {
if self.content.is_none() {
EditOperationKind::Deletion
@ -120,6 +106,12 @@ impl PartialOrd for Edit {
}
}
impl Ranged for Edit {
fn range(&self) -> TextRange {
self.range
}
}
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
enum EditOperationKind {
/// Edit that inserts new content into the source document.