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

Method consider_decorator

codegraph-kernel/src/python.rs:660–705  ·  view source on GitHub ↗
(&mut self, n: Node<'t>, decorated_row: u32)

Source from the content-addressed store, hash-verified

658 }
659
660 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
661 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {
662 return;
663 }
664 let mut target: Option<Node> = None;
665 for i in 0..n.named_child_count() {
666 let Some(child) = n.named_child(i) else { continue };
667 if child.kind() == "call_expression" {
668 target = child.child_by_field_name("function").or_else(|| child.named_child(0));
669 if target.is_some() {
670 break;
671 }
672 }
673 if matches!(
674 child.kind(),
675 "identifier" | "member_expression" | "scoped_identifier" | "navigation_expression"
676 | "user_type" | "type_identifier"
677 ) {
678 target = Some(child);
679 break;
680 }
681 }
682 let Some(target) = target else { return };
683 let mut name = self.text(target).to_string();
684 if let Some(lt) = name.find('<') {
685 if lt > 0 {
686 name.truncate(lt);
687 }
688 }
689 let last_dot = name
690 .rfind('.')
691 .map(|i| i as isize)
692 .unwrap_or(-1)
693 .max(name.rfind("::").map(|i| i as isize).unwrap_or(-1));
694 if last_dot >= 0 {
695 name = name[(last_dot as usize + 1)..].to_string();
696 if name.starts_with(':') || name.starts_with('.') {
697 name.remove(0);
698 }
699 }
700 let name = name.trim().to_string();
701 if name.is_empty() {
702 return;
703 }
704 self.push_ref_at(decorated_row, &name, edge_kind_index("decorates").unwrap(), n);
705 }
706
707 // --- fn refs (PYTHON_SPEC) ------------------------------------------------------
708

Callers 1

Calls 4

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
textMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected