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

Method extract_call

codegraph-kernel/src/swift.rs:984–1068  ·  view source on GitHub ↗

extractCall — swift rides the generic member branch (navigation) and the raw-text else; the full matrix is in the checklist.

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

Source from the content-addressed store, hash-verified

982 /// extractCall — swift rides the generic member branch (navigation) and
983 /// the raw-text else; the full matrix is in the checklist.
984 fn extract_call(&mut self, node: Node<'t>) {
985 if self.stack.is_empty() {
986 return;
987 }
988 let caller = self.top_row();
989 let func = node
990 .child_by_field_name("function")
991 .or_else(|| node.named_child(0));
992 let Some(func) = func else { return };
993 let mut callee_name = String::new();
994
995 if func.kind() == "navigation_expression" {
996 // property = property/field fields (null) → namedChild(1), with
997 // the navigation_suffix simple_identifier unwrap.
998 let property = func
999 .child_by_field_name("property")
1000 .or_else(|| func.child_by_field_name("field"))
1001 .or_else(|| {
1002 let c1 = func.named_child(1);
1003 match c1 {
1004 Some(c) if c.kind() == "navigation_suffix" => (0..c.named_child_count())
1005 .filter_map(|i| c.named_child(i))
1006 .find(|g| g.kind() == "simple_identifier")
1007 .or(Some(c)),
1008 other => other,
1009 }
1010 });
1011 if let Some(property) = property {
1012 let method_name = self.text(property);
1013 let receiver = func
1014 .child_by_field_name("object")
1015 .or_else(|| func.child_by_field_name("operand"))
1016 .or_else(|| func.child_by_field_name("argument"))
1017 .or_else(|| func.named_child(0));
1018 if let Some(r) = receiver {
1019 if is_literal_receiver(r.kind()) {
1020 return; // `"lit".upper()` / `5.times()` — nothing
1021 }
1022 }
1023 let recv_ident = receiver.filter(|r| {
1024 matches!(r.kind(), "identifier" | "simple_identifier" | "field_identifier")
1025 });
1026 if let Some(r) = recv_ident {
1027 let receiver_name = self.text(r);
1028 if matches!(receiver_name, "self" | "this" | "cls" | "super") {
1029 callee_name = method_name.to_string();
1030 } else {
1031 callee_name = format!("{receiver_name}.{method_name}");
1032 }
1033 } else if receiver.map(|r| r.kind() == "call_expression").unwrap_or(false) {
1034 // #750 swift re-encode: innerNav = receiver.namedChild(0),
1035 // ws-stripped; capitalized chains only.
1036 let inner = receiver.unwrap().named_child(0);
1037 let inner_callee =
1038 inner.map(|n| strip_js_ws(self.text(n))).unwrap_or_default();
1039 let reencode = inner_callee
1040 .as_bytes()
1041 .first()

Callers 2

visit_nodeMethod · 0.45

Calls 7

edge_kind_indexFunction · 0.85
is_literal_receiverFunction · 0.70
strip_js_wsFunction · 0.70
unwrapMethod · 0.60
top_rowMethod · 0.45
textMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected