mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 03:15:44 +00:00
Preserve comments on non-defaulted arguments (#3264)
This commit is contained in:
parent
16be691712
commit
470e1c1754
8 changed files with 87 additions and 189 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::core::visitor;
|
||||
use crate::core::visitor::Visitor;
|
||||
use crate::cst::{Alias, Body, Excepthandler, Expr, Pattern, SliceIndex, Stmt};
|
||||
use crate::cst::{Alias, Arg, Body, Excepthandler, Expr, Pattern, SliceIndex, Stmt};
|
||||
use crate::trivia::{decorate_trivia, TriviaIndex, TriviaToken};
|
||||
|
||||
struct AttachmentVisitor {
|
||||
|
@ -40,6 +40,14 @@ impl<'a> Visitor<'a> for AttachmentVisitor {
|
|||
visitor::walk_alias(self, alias);
|
||||
}
|
||||
|
||||
fn visit_arg(&mut self, arg: &'a mut Arg) {
|
||||
let trivia = self.index.arg.remove(&arg.id());
|
||||
if let Some(comments) = trivia {
|
||||
arg.trivia.extend(comments);
|
||||
}
|
||||
visitor::walk_arg(self, arg);
|
||||
}
|
||||
|
||||
fn visit_excepthandler(&mut self, excepthandler: &'a mut Excepthandler) {
|
||||
let trivia = self.index.excepthandler.remove(&excepthandler.id());
|
||||
if let Some(comments) = trivia {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue