Formatter: Show preceding, following and enclosing nodes of comments, Attempt 2 (#6813)

This commit is contained in:
konsti 2023-09-06 12:26:13 +02:00 committed by GitHub
parent e3114a144c
commit 447b7cb0e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 32 deletions

View file

@ -108,7 +108,8 @@ use ruff_python_trivia::PythonWhitespace;
use crate::comments::debug::{DebugComment, DebugComments};
use crate::comments::map::{LeadingDanglingTrailing, MultiMap};
use crate::comments::node_key::NodeRefEqualityKey;
use crate::comments::visitor::CommentsVisitor;
use crate::comments::visitor::{CommentsMapBuilder, CommentsVisitor};
pub(crate) use visitor::collect_comments;
mod debug;
pub(crate) mod format;
@ -324,7 +325,9 @@ impl<'a> Comments<'a> {
let map = if comment_ranges.is_empty() {
CommentsMap::new()
} else {
CommentsVisitor::new(source_code, comment_ranges).visit(root)
let mut builder = CommentsMapBuilder::default();
CommentsVisitor::new(source_code, comment_ranges, &mut builder).visit(root);
builder.finish()
};
Self::new(map)