mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-10 05:39:12 +00:00
add DebugText
for self-documenting f-strings (#6167)
This commit is contained in:
parent
44a8d1c644
commit
ba990b676f
26 changed files with 148 additions and 155 deletions
|
@ -592,6 +592,7 @@ pub struct ExprCall<'a> {
|
|||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ExprFormattedValue<'a> {
|
||||
value: Box<ComparableExpr<'a>>,
|
||||
debug_text: Option<&'a ast::DebugText>,
|
||||
conversion: ast::ConversionFlag,
|
||||
format_spec: Option<Box<ComparableExpr<'a>>>,
|
||||
}
|
||||
|
@ -849,11 +850,13 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
ast::Expr::FormattedValue(ast::ExprFormattedValue {
|
||||
value,
|
||||
conversion,
|
||||
debug_text,
|
||||
format_spec,
|
||||
range: _range,
|
||||
}) => Self::FormattedValue(ExprFormattedValue {
|
||||
value: value.into(),
|
||||
conversion: *conversion,
|
||||
debug_text: debug_text.as_ref(),
|
||||
format_spec: format_spec.as_ref().map(Into::into),
|
||||
}),
|
||||
ast::Expr::JoinedStr(ast::ExprJoinedStr {
|
||||
|
|
|
@ -888,6 +888,7 @@ impl From<ExprCall> for Expr {
|
|||
pub struct ExprFormattedValue {
|
||||
pub range: TextRange,
|
||||
pub value: Box<Expr>,
|
||||
pub debug_text: Option<DebugText>,
|
||||
pub conversion: ConversionFlag,
|
||||
pub format_spec: Option<Box<Expr>>,
|
||||
}
|
||||
|
@ -925,6 +926,14 @@ impl ConversionFlag {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct DebugText {
|
||||
/// The text between the `{` and the expression node.
|
||||
pub leading: String,
|
||||
/// The text between the expression and the conversion, the format_spec, or the `}`, depending on what's present in the source
|
||||
pub trailing: String,
|
||||
}
|
||||
|
||||
/// See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprJoinedStr {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue