Add definitions for match statement (#13147)

## Summary

This PR adds definition for match patterns.

## Test Plan

Update the existing test case for match statement symbols to verify that
the definitions are added as well.
This commit is contained in:
Dhruv Manilawala 2024-09-02 14:40:09 +05:30 committed by GitHub
parent 9986397d56
commit 17eb65b26f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 189 additions and 16 deletions

View file

@ -1,12 +1,18 @@
use ruff_python_ast::{AnyNodeRef, NodeKind};
use ruff_python_ast::{AnyNodeRef, Identifier, 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: NodeKind,
kind: Kind,
range: TextRange,
}
@ -17,8 +23,15 @@ impl NodeKey {
{
let node = node.into();
NodeKey {
kind: node.kind(),
kind: Kind::Node(node.kind()),
range: node.range(),
}
}
pub(super) fn from_identifier(identifier: &Identifier) -> Self {
NodeKey {
kind: Kind::Identifier,
range: identifier.range(),
}
}
}