mirror of
https://github.com/astral-sh/ruff
synced 2026-01-09 23:54:36 -05:00
Visit Identifier node as part of the SourceOrderVisitor (#17110)
## Summary I don't remember exactly when we made `Identifier` a node but it is now considered a node (it implements `AnyNodeRef`, it has a range). However, we never updated the `SourceOrderVisitor` to visit identifiers because we never had a use case for it and visiting new nodes can change how the formatter associates comments (breaking change!). This PR updates the `SourceOrderVisitor` to visit identifiers and changes the formatter comment visitor to skip identifiers (updating the visitor might be desired because it could help simplifying some comment placement logic but this is out of scope for this PR). ## Test Plan Tests, updated snapshot tests
This commit is contained in:
@@ -2,7 +2,7 @@ use std::fmt::Debug;
|
||||
use std::iter::Peekable;
|
||||
|
||||
use ruff_formatter::{SourceCode, SourceCodeSlice};
|
||||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{AnyNodeRef, Identifier};
|
||||
use ruff_python_ast::{Mod, Stmt};
|
||||
// The interface is designed to only export the members relevant for iterating nodes in
|
||||
// pre-order.
|
||||
@@ -166,6 +166,10 @@ impl<'ast> SourceOrderVisitor<'ast> for CommentsVisitor<'ast, '_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_identifier(&mut self, _identifier: &'ast Identifier) {
|
||||
// TODO: Visit and associate comments with identifiers
|
||||
}
|
||||
}
|
||||
|
||||
/// A comment decorated with additional information about its surrounding context in the source document.
|
||||
|
||||
Reference in New Issue
Block a user