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

Method extract_decorators_for

codegraph-kernel/src/python.rs:625–656  ·  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

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