Optional source map generation (#6894)

This commit is contained in:
Micha Reiser 2023-08-26 18:00:43 +02:00 committed by GitHub
parent 15b73bdb8a
commit eae59cf088
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 117 additions and 73 deletions

View file

@ -1,11 +1,8 @@
use thiserror::Error;
use ruff_formatter::format_element::tag;
use ruff_formatter::prelude::{source_position, text, Formatter, Tag};
use ruff_formatter::{
format, write, Buffer, Format, FormatElement, FormatError, FormatResult, PrintError,
};
use ruff_formatter::{Formatted, Printed, SourceCode};
use ruff_formatter::prelude::*;
use ruff_formatter::{format, FormatError, Formatted, PrintError, Printed, SourceCode};
use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_ast::Mod;
use ruff_python_index::{CommentRanges, CommentRangesBuilder};
@ -54,23 +51,22 @@ where
if self.is_suppressed(node_comments.trailing, f.context()) {
suppressed_node(node.as_any_node_ref()).fmt(f)
} else {
write!(
f,
[
leading_comments(node_comments.leading),
source_position(node.start())
]
)?;
leading_comments(node_comments.leading).fmt(f)?;
let is_source_map_enabled = f.options().source_map_generation().is_enabled();
if is_source_map_enabled {
source_position(node.start()).fmt(f)?;
}
self.fmt_fields(node, f)?;
self.fmt_dangling_comments(node_comments.dangling, f)?;
write!(
f,
[
source_position(node.end()),
trailing_comments(node_comments.trailing)
]
)
if is_source_map_enabled {
source_position(node.end()).fmt(f)?;
}
trailing_comments(node_comments.trailing).fmt(f)
}
}