mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:30 +00:00
Add comments option to playground (#6911)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
e615870659
commit
fa25dabf17
9 changed files with 163 additions and 21 deletions
|
@ -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>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue