Add comments option to playground (#6911)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Chris Pryer 2023-08-28 03:26:23 -04:00 committed by GitHub
parent e615870659
commit fa25dabf17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 163 additions and 21 deletions

View file

@ -14,7 +14,7 @@ use ruff_text_size::TextLen;
use crate::comments::{
dangling_comments, leading_comments, trailing_comments, Comments, SourceComment,
};
use crate::context::PyFormatContext;
pub use crate::context::PyFormatContext;
pub use crate::options::{MagicTrailingComma, PyFormatOptions, QuoteStyle};
use crate::verbatim::suppressed_node;
@ -167,6 +167,17 @@ pub fn format_node<'a>(
Ok(formatted)
}
/// Public function for generating a printable string of the debug comments.
pub fn pretty_comments(formatted: &Formatted<PyFormatContext>, source: &str) -> String {
let comments = formatted.context().comments();
// When comments are empty we'd display an empty map '{}'
std::format!(
"{comments:#?}",
comments = comments.debug(SourceCode::new(source))
)
}
pub(crate) struct NotYetImplementedCustomText<'a> {
text: &'static str,
node: AnyNodeRef<'a>,