mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00
Add builders for common comment rendering (#3232)
This commit is contained in:
parent
a8a312e862
commit
51bca19c1d
13 changed files with 195 additions and 433 deletions
|
@ -1,8 +1,9 @@
|
|||
use ruff_formatter::prelude::*;
|
||||
use ruff_formatter::{write, Format};
|
||||
use ruff_text_size::TextSize;
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
|
||||
use crate::context::ASTFormatContext;
|
||||
use crate::core::types::Range;
|
||||
use crate::cst::Stmt;
|
||||
use crate::shared_traits::AsFormat;
|
||||
|
||||
|
@ -28,6 +29,26 @@ pub fn block(body: &[Stmt]) -> Block {
|
|||
Block { body }
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct Literal {
|
||||
range: Range,
|
||||
}
|
||||
|
||||
impl Format<ASTFormatContext<'_>> for Literal {
|
||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
||||
let (text, start, end) = f.context().locator().slice(self.range);
|
||||
f.write_element(FormatElement::StaticTextSlice {
|
||||
text,
|
||||
range: TextRange::new(start.try_into().unwrap(), end.try_into().unwrap()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn literal(range: Range) -> Literal {
|
||||
Literal { range }
|
||||
}
|
||||
|
||||
pub(crate) const fn join_names(names: &[String]) -> JoinNames {
|
||||
JoinNames { names }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue