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

Method extract_call

codegraph-kernel/src/ruby.rs:760–824  ·  view source on GitHub ↗

extractCall — the bespoke ruby branch (tree-sitter.ts:3905-3960), reached only from the body walker.

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

758 /// extractCall — the bespoke ruby branch (tree-sitter.ts:3905-3960),
759 /// reached only from the body walker.
760 fn extract_call(&mut self, node: Node<'t>) {
761 if self.stack.is_empty() {
762 return;
763 }
764 let caller = self.top_row();
765 let method_name = match node.child_by_field_name("method") {
766 Some(m) => self.text(m),
767 None => "",
768 };
769 if method_name.is_empty() {
770 return; // operator/element-reference call with no method name
771 }
772 let line = self.line_of(node);
773 let col = self.col_of(node);
774 let calls_kind = edge_kind_index("calls").unwrap();
775
776 let Some(receiver) = node.child_by_field_name("receiver") else {
777 // Bare `foo(...)` — just the method name.
778 self.push_ref(caller, &method_name.to_string(), calls_kind, line, col);
779 return;
780 };
781 let receiver_name = self.text(receiver);
782
783 // `Foo.new` / `NS::Widget.new` → instantiates ref to the LAST `::`
784 // segment; a non-capitalized receiver falls through to a calls ref
785 // (`lower.new`).
786 if method_name == "new" {
787 let class_name = match receiver_name.rfind("::") {
788 Some(i) => &receiver_name[i + 2..],
789 None => receiver_name,
790 };
791 if class_name.as_bytes().first().map(|b| b.is_ascii_uppercase()).unwrap_or(false) {
792 self.push_ref(
793 caller,
794 &class_name.to_string(),
795 edge_kind_index("instantiates").unwrap(),
796 line,
797 col,
798 );
799 return;
800 }
801 }
802
803 // SKIP_RECEIVERS by TEXT — ruby's set is {self, super} only. `&.`
804 // joins with a plain `.`; chains/literals keep raw receiver text.
805 let skip = matches!(receiver_name, "self" | "super");
806 let callee = if skip {
807 method_name.to_string()
808 } else {
809 format!("{receiver_name}.{method_name}")
810 };
811 self.push_ref(caller, &callee, calls_kind, line, col);
812
813 // Capitalized constant receiver (`Klass.static_call`, `RETRY_MAX.times`)
814 // → an ADDITIONAL references ref at the RECEIVER's position.
815 // (scope_resolution receivers get none — type ≠ constant.)
816 if !skip && receiver.kind() == "constant" {
817 self.push_ref_at(

Callers 1

Calls 8

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
top_rowMethod · 0.45
textMethod · 0.45
line_ofMethod · 0.45
col_ofMethod · 0.45
push_refMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected