mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00
Fix build (#7437)
This commit is contained in:
parent
916dd5b7fa
commit
c907317199
3 changed files with 23 additions and 10 deletions
|
@ -305,15 +305,15 @@ pub(crate) struct Comments<'a> {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
data: Rc<CommentsData<'a>>,
|
data: Rc<CommentsData<'a>>,
|
||||||
/// We need those for backwards lexing
|
|
||||||
comment_ranges: &'a CommentRanges,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Comments<'a> {
|
impl<'a> Comments<'a> {
|
||||||
fn new(comments: CommentsMap<'a>, comment_ranges: &'a CommentRanges) -> Self {
|
fn new(comments: CommentsMap<'a>, comment_ranges: &'a CommentRanges) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: Rc::new(CommentsData { comments }),
|
data: Rc::new(CommentsData {
|
||||||
|
comments,
|
||||||
comment_ranges,
|
comment_ranges,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,13 +321,15 @@ impl<'a> Comments<'a> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn from_ranges(comment_ranges: &'a CommentRanges) -> Self {
|
pub(crate) fn from_ranges(comment_ranges: &'a CommentRanges) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: Rc::new(CommentsData::default()),
|
data: Rc::new(CommentsData {
|
||||||
|
comments: CommentsMap::default(),
|
||||||
comment_ranges,
|
comment_ranges,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ranges(&self) -> &'a CommentRanges {
|
pub(crate) fn ranges(&self) -> &'a CommentRanges {
|
||||||
self.comment_ranges
|
self.data.comment_ranges
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts the comments from the AST.
|
/// Extracts the comments from the AST.
|
||||||
|
@ -521,9 +523,12 @@ impl LeadingDanglingTrailingComments<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug)]
|
||||||
struct CommentsData<'a> {
|
struct CommentsData<'a> {
|
||||||
comments: CommentsMap<'a>,
|
comments: CommentsMap<'a>,
|
||||||
|
|
||||||
|
/// We need those for backwards lexing
|
||||||
|
comment_ranges: &'a CommentRanges,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MarkVerbatimCommentsAsFormattedVisitor<'a>(&'a Comments<'a>);
|
struct MarkVerbatimCommentsAsFormattedVisitor<'a>(&'a Comments<'a>);
|
||||||
|
|
|
@ -38,7 +38,11 @@ impl FormatNodeRule<ExprCall> for FormatExprCall {
|
||||||
|
|
||||||
let fmt_func = format_with(|f: &mut PyFormatter| {
|
let fmt_func = format_with(|f: &mut PyFormatter| {
|
||||||
// Format the function expression.
|
// Format the function expression.
|
||||||
if is_expression_parenthesized(func.into(), f.context().source()) {
|
if is_expression_parenthesized(
|
||||||
|
func.into(),
|
||||||
|
f.context().comments().ranges(),
|
||||||
|
f.context().source(),
|
||||||
|
) {
|
||||||
func.format().with_options(Parentheses::Always).fmt(f)
|
func.format().with_options(Parentheses::Always).fmt(f)
|
||||||
} else {
|
} else {
|
||||||
match func.as_ref() {
|
match func.as_ref() {
|
||||||
|
|
|
@ -43,7 +43,11 @@ impl FormatNodeRule<ExprSubscript> for FormatExprSubscript {
|
||||||
);
|
);
|
||||||
|
|
||||||
let format_inner = format_with(|f: &mut PyFormatter| {
|
let format_inner = format_with(|f: &mut PyFormatter| {
|
||||||
if is_expression_parenthesized(value.into(), f.context().source()) {
|
if is_expression_parenthesized(
|
||||||
|
value.into(),
|
||||||
|
f.context().comments().ranges(),
|
||||||
|
f.context().source(),
|
||||||
|
) {
|
||||||
value.format().with_options(Parentheses::Always).fmt(f)
|
value.format().with_options(Parentheses::Always).fmt(f)
|
||||||
} else {
|
} else {
|
||||||
match value.as_ref() {
|
match value.as_ref() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue