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

Method extract_call

codegraph-kernel/src/ruby.rs:767–831  ·  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

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

Callers 1

Calls 8

edge_kind_indexFunction · 0.85
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 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