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:
Micha Reiser 2025-04-01 16:58:09 +02:00 committed by GitHub
parent 49c25993eb
commit 5a876ed25e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 142 additions and 35 deletions

View file

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