MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_decorators_for

Method extract_decorators_for

codegraph-kernel/src/python.rs:633–664  ·  view source on GitHub ↗

extractDecoratorsFor — python decorators are PRECEDING SIBLINGS inside decorated_definition. Only bare-identifier decorators yield a target (python's `call` kind isn't `call_expression`, and `attribute` isn't in the target-kind list — mirrored exactly).

(&mut self, decl: Node<'t>, decorated_row: u32)

Source from the content-addressed store, hash-verified

631 /// (python's `call` kind isn't `call_expression`, and `attribute` isn't in
632 /// the target-kind list — mirrored exactly).
633 fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
634 for i in 0..decl.named_child_count() {
635 if let Some(child) = decl.named_child(i) {
636 self.consider_decorator(child, decorated_row);
637 }
638 }
639 let Some(parent) = decl.parent() else { return };
640 let decl_start = decl.start_byte();
641 let mut decl_idx: isize = -1;
642 for i in 0..parent.named_child_count() {
643 if let Some(sib) = parent.named_child(i) {
644 if sib.start_byte() == decl_start {
645 decl_idx = i as isize;
646 break;
647 }
648 }
649 }
650 if decl_idx > 0 {
651 let mut j = decl_idx - 1;
652 while j >= 0 {
653 let Some(sib) = parent.named_child(j as usize) else {
654 j -= 1;
655 continue;
656 };
657 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
658 break;
659 }
660 self.consider_decorator(sib, decorated_row);
661 j -= 1;
662 }
663 }
664 }
665
666 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
667 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 3

extract_functionMethod · 0.45
extract_methodMethod · 0.45
extract_classMethod · 0.45

Calls 1

consider_decoratorMethod · 0.45

Tested by

no test coverage detected