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

Method extract_call

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

792 /// extractCall — the bespoke ruby branch (tree-sitter.ts:3905-3960),
793 /// reached only from the body walker.
794 fn extract_call(&mut self, node: Node<'t>) {
795 if self.stack.is_empty() {
796 return;
797 }
798 let caller = self.top_row();
799 let method_name = match node.child_by_field_name("method") {
800 Some(m) => self.text(m),
801 None => "",
802 };
803 if method_name.is_empty() {
804 return; // operator/element-reference call with no method name
805 }
806 let line = self.line_of(node);
807 let col = self.col_of(node);
808 let calls_kind = edge_kind_index("calls").unwrap();
809
810 let Some(receiver) = node.child_by_field_name("receiver") else {
811 // Bare `foo(...)` — just the method name.
812 self.push_ref(caller, &method_name.to_string(), calls_kind, line, col);
813 return;
814 };
815 let receiver_name = self.text(receiver);
816
817 // `Foo.new` / `NS::Widget.new` → instantiates ref to the LAST `::`
818 // segment; a non-capitalized receiver falls through to a calls ref
819 // (`lower.new`).
820 if method_name == "new" {
821 let class_name = match receiver_name.rfind("::") {
822 Some(i) => &receiver_name[i + 2..],
823 None => receiver_name,
824 };
825 if class_name.as_bytes().first().map(|b| b.is_ascii_uppercase()).unwrap_or(false) {
826 self.push_ref(
827 caller,
828 &class_name.to_string(),
829 edge_kind_index("instantiates").unwrap(),
830 line,
831 col,
832 );
833 return;
834 }
835 }
836
837 // SKIP_RECEIVERS by TEXT — ruby's set is {self, super} only. `&.`
838 // joins with a plain `.`; chains/literals keep raw receiver text.
839 let skip = matches!(receiver_name, "self" | "super");
840 let callee = if skip {
841 method_name.to_string()
842 } else if let Some(class_name) = self.constructed_class(receiver) {
843 // A call on what `Foo.new(…)` made: `new Foo().m`, not the
844 // receiver's text with its arguments in it (#684).
845 format!("new {class_name}().{method_name}")
846 } else {
847 format!("{receiver_name}.{method_name}")
848 };
849 self.push_ref(caller, &callee, calls_kind, line, col);
850
851 // Capitalized constant receiver (`Klass.static_call`, `RETRY_MAX.times`),

Callers 1

Calls 12

edge_kind_indexFunction · 0.85
is_constant_pathFunction · 0.85
mapMethod · 0.80
constructed_classMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
line_ofMethod · 0.45
col_ofMethod · 0.45
push_refMethod · 0.45
firstMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected