Preserve comments on non-defaulted arguments (#3264)

This commit is contained in:
Charlie Marsh 2023-02-27 18:41:40 -05:00 committed by GitHub
parent 16be691712
commit 470e1c1754
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 87 additions and 189 deletions

View file

@ -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 {