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

Method extract_decorators_for

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

807 /// (python's `call` kind isn't `call_expression`, and `attribute` isn't in
808 /// the target-kind list — mirrored exactly).
809 fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
810 for i in 0..decl.named_child_count() {
811 if let Some(child) = decl.named_child(i) {
812 self.consider_decorator(child, decorated_row);
813 }
814 }
815 let Some(parent) = decl.parent() else { return };
816 let decl_start = decl.start_byte();
817 let mut decl_idx: isize = -1;
818 for i in 0..parent.named_child_count() {
819 if let Some(sib) = parent.named_child(i) {
820 if sib.start_byte() == decl_start {
821 decl_idx = i as isize;
822 break;
823 }
824 }
825 }
826 if decl_idx > 0 {
827 let mut j = decl_idx - 1;
828 while j >= 0 {
829 let Some(sib) = parent.named_child(j as usize) else {
830 j -= 1;
831 continue;
832 };
833 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
834 break;
835 }
836 self.consider_decorator(sib, decorated_row);
837 j -= 1;
838 }
839 }
840 }
841
842 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
843 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