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

Method extract_call

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

814 /// extractCall — the bespoke ruby branch (tree-sitter.ts:3905-3960),
815 /// reached only from the body walker.
816 fn extract_call(&mut self, node: Node<'t>) {
817 if self.stack.is_empty() {
818 return;
819 }
820 let caller = self.top_row();
821 let method_name = match node.child_by_field_name("method") {
822 Some(m) => self.text(m),
823 None => "",
824 };
825 if method_name.is_empty() {
826 return; // operator/element-reference call with no method name
827 }
828 let line = self.line_of(node);
829 let col = self.col_of(node);
830 let calls_kind = edge_kind_index("calls").unwrap();
831
832 let Some(receiver) = node.child_by_field_name("receiver") else {
833 // Bare `foo(...)` — just the method name.
834 self.push_ref(caller, &method_name.to_string(), calls_kind, line, col);
835 return;
836 };
837 let receiver_name = self.text(receiver);
838
839 // `Foo.new` / `NS::Widget.new` → instantiates ref to the LAST `::`
840 // segment; a non-capitalized receiver falls through to a calls ref
841 // (`lower.new`).
842 if method_name == "new" {
843 let class_name = match receiver_name.rfind("::") {
844 Some(i) => &receiver_name[i + 2..],
845 None => receiver_name,
846 };
847 if class_name.as_bytes().first().map(|b| b.is_ascii_uppercase()).unwrap_or(false) {
848 self.push_ref(
849 caller,
850 &class_name.to_string(),
851 edge_kind_index("instantiates").unwrap(),
852 line,
853 col,
854 );
855 return;
856 }
857 }
858
859 // SKIP_RECEIVERS by TEXT — ruby's set is {self, super} only. `&.`
860 // joins with a plain `.`; chains/literals keep raw receiver text.
861 let skip = matches!(receiver_name, "self" | "super");
862 let callee = if skip {
863 method_name.to_string()
864 } else if let Some(class_name) = self.constructed_class(receiver) {
865 // A call on what `Foo.new(…)` made: `new Foo().m`, not the
866 // receiver's text with its arguments in it (#684).
867 format!("new {class_name}().{method_name}")
868 } else {
869 format!("{receiver_name}.{method_name}")
870 };
871 self.push_ref(caller, &callee, calls_kind, line, col);
872
873 // 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