mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 01:20:24 +00:00
Implement AstNode
for Identifier
(#13207)
## Summary Follow-up to #13147, this PR implements the `AstNode` for `Identifier`. This makes it easier to create the `NodeKey` in red knot because it uses a generic method to construct the key from `AnyNodeRef` and is important for definitions that are created only on identifiers instead of `ExprName`. ## Test Plan `cargo test` and `cargo clippy`
This commit is contained in:
parent
f4bed22b05
commit
47f0b45be3
5 changed files with 80 additions and 18 deletions
|
@ -1,18 +1,12 @@
|
|||
use ruff_python_ast::{AnyNodeRef, Identifier, NodeKind};
|
||||
use ruff_python_ast::{AnyNodeRef, NodeKind};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(super) enum Kind {
|
||||
Node(NodeKind),
|
||||
Identifier,
|
||||
}
|
||||
|
||||
/// Compact key for a node for use in a hash map.
|
||||
///
|
||||
/// Compares two nodes by their kind and text range.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(super) struct NodeKey {
|
||||
kind: Kind,
|
||||
kind: NodeKind,
|
||||
range: TextRange,
|
||||
}
|
||||
|
||||
|
@ -23,15 +17,8 @@ impl NodeKey {
|
|||
{
|
||||
let node = node.into();
|
||||
NodeKey {
|
||||
kind: Kind::Node(node.kind()),
|
||||
kind: node.kind(),
|
||||
range: node.range(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn from_identifier(identifier: &Identifier) -> Self {
|
||||
NodeKey {
|
||||
kind: Kind::Identifier,
|
||||
range: identifier.range(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue