mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
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:
parent
fc89976c24
commit
059757a8c8
23 changed files with 104 additions and 115 deletions
|
@ -1,8 +1,10 @@
|
|||
mod call_stack;
|
||||
mod line_suffixes;
|
||||
mod printer_options;
|
||||
mod queue;
|
||||
mod stack;
|
||||
use std::num::NonZeroU8;
|
||||
|
||||
use drop_bomb::DebugDropBomb;
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
|
||||
pub use printer_options::*;
|
||||
use ruff_text_size::{Ranged, TextLen, TextSize};
|
||||
|
||||
use crate::format_element::document::Document;
|
||||
use crate::format_element::tag::{Condition, GroupMode};
|
||||
|
@ -21,11 +23,12 @@ use crate::{
|
|||
ActualStart, FormatElement, GroupId, IndentStyle, InvalidDocumentError, PrintError,
|
||||
PrintResult, Printed, SourceMarker, TextRange,
|
||||
};
|
||||
use drop_bomb::DebugDropBomb;
|
||||
pub use printer_options::*;
|
||||
use ruff_text_size::{TextLen, TextSize};
|
||||
use std::num::NonZeroU8;
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
|
||||
mod call_stack;
|
||||
mod line_suffixes;
|
||||
mod printer_options;
|
||||
mod queue;
|
||||
mod stack;
|
||||
|
||||
/// Prints the format elements into a string
|
||||
#[derive(Debug, Default)]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use ruff_text_size::{TextRange, TextSize};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
/// The source code of a document that gets formatted
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)]
|
||||
pub struct SourceCode<'a> {
|
||||
|
@ -67,18 +68,12 @@ impl SourceCodeSlice {
|
|||
assert!(usize::from(self.range.end()) <= code.text.len(), "The range of this slice is out of bounds. Did you provide the correct source code for this slice?");
|
||||
&code.text[self.range]
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn range(&self) -> TextRange {
|
||||
impl Ranged for SourceCodeSlice {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
|
||||
pub const fn start(&self) -> TextSize {
|
||||
self.range.start()
|
||||
}
|
||||
|
||||
pub const fn end(&self) -> TextSize {
|
||||
self.range.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for SourceCodeSlice {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue