Format ExpressionStarred nodes (#5654)

This commit is contained in:
Micha Reiser 2023-07-11 08:08:08 +02:00 committed by GitHub
parent 9f486fa841
commit 987111f5fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 192 additions and 581 deletions

View file

@ -38,6 +38,7 @@ pub(super) fn place_comment<'a>(
handle_slice_comments,
handle_attribute_comment,
handle_expr_if_comment,
handle_trailing_expression_starred_star_end_of_line_comment,
];
for handler in HANDLERS {
comment = match handler(comment, locator) {
@ -1215,6 +1216,21 @@ fn handle_expr_if_comment<'a>(
CommentPlacement::Default(comment)
}
fn handle_trailing_expression_starred_star_end_of_line_comment<'a>(
comment: DecoratedComment<'a>,
_locator: &Locator,
) -> CommentPlacement<'a> {
if comment.line_position().is_own_line() || comment.following_node().is_none() {
return CommentPlacement::Default(comment);
}
let AnyNodeRef::ExprStarred(starred) = comment.enclosing_node() else {
return CommentPlacement::Default(comment);
};
CommentPlacement::leading(starred.as_any_node_ref(), comment)
}
/// Looks for a token in the range that contains no other tokens except for parentheses outside
/// the expression ranges
fn find_only_token_in_range(range: TextRange, locator: &Locator, token_kind: TokenKind) -> Token {