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

Method extract_call

codegraph-kernel/src/swift.rs:996–1080  ·  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

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

Callers 2

visit_nodeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected