Attach dangling comments to the comprehension instead of the if or iter nodes (#7693)

This commit is contained in:
Micha Reiser 2023-09-29 11:45:01 +02:00 committed by GitHub
parent e62e245c61
commit e2ec42539b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 124 additions and 22 deletions

View file

@ -2083,7 +2083,7 @@ fn handle_comprehension_comment<'a>(
CommentPlacement::Default(comment)
} else {
// after the `for`
CommentPlacement::dangling(comment.enclosing_node(), comment)
CommentPlacement::dangling(comprehension, comment)
};
}
@ -2106,7 +2106,7 @@ fn handle_comprehension_comment<'a>(
// attach as dangling comments on the target
// (to be rendered as leading on the "in")
return if is_own_line {
CommentPlacement::dangling(comment.enclosing_node(), comment)
CommentPlacement::dangling(comprehension, comment)
} else {
// correctly trailing on the target
CommentPlacement::Default(comment)
@ -2126,7 +2126,7 @@ fn handle_comprehension_comment<'a>(
CommentPlacement::Default(comment)
} else {
// after the `in` but same line, turn into trailing on the `in` token
CommentPlacement::dangling(&comprehension.iter, comment)
CommentPlacement::dangling(comprehension, comment)
};
}
@ -2157,10 +2157,10 @@ fn handle_comprehension_comment<'a>(
);
if is_own_line {
if last_end < comment.start() && comment.start() < if_token.start() {
return CommentPlacement::dangling(if_node, comment);
return CommentPlacement::dangling(comprehension, comment);
}
} else if if_token.start() < comment.start() && comment.start() < if_node.start() {
return CommentPlacement::dangling(if_node, comment);
return CommentPlacement::dangling(comprehension, comment);
}
last_end = if_node.end();
}