ruff/crates/ruff_python_formatter/src/context.rs
2023-05-11 15:43:42 +00:00

36 lines
743 B
Rust

use std::rc::Rc;
use ruff_formatter::{FormatContext, SimpleFormatOptions};
use ruff_python_ast::source_code::Locator;
pub struct ASTFormatContext {
options: SimpleFormatOptions,
contents: Rc<str>,
}
impl ASTFormatContext {
pub fn new(options: SimpleFormatOptions, contents: &str) -> Self {
Self {
options,
contents: Rc::from(contents),
}
}
}
impl FormatContext for ASTFormatContext {
type Options = SimpleFormatOptions;
fn options(&self) -> &Self::Options {
&self.options
}
}
impl ASTFormatContext {
pub fn contents(&self) -> Rc<str> {
self.contents.clone()
}
pub fn locator(&self) -> Locator {
Locator::new(&self.contents)
}
}