mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 08:00:19 +00:00
Optional source map generation (#6894)
This commit is contained in:
parent
15b73bdb8a
commit
eae59cf088
7 changed files with 117 additions and 73 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue