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

Method extract_call

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

1065 /// extractCall — swift rides the generic member branch (navigation) and
1066 /// the raw-text else; the full matrix is in the checklist.
1067 fn extract_call(&mut self, node: Node<'t>) {
1068 if self.stack.is_empty() {
1069 return;
1070 }
1071 let caller = self.top_row();
1072 let func = node
1073 .child_by_field_name("function")
1074 .or_else(|| node.named_child(0));
1075 let Some(func) = func else { return };
1076 // `-(a + b)`: an operator token applied to a parenthesized value leaves
1077 // the call with no callee node, only its arguments (tree-sitter.ts).
1078 // `!(x)` keeps its `bang` callee: a project may declare `prefix func !`.
1079 if func.kind() == "call_suffix" {
1080 return;
1081 }
1082 let func = peel_call_wrappers(func, self.src);
1083 let mut callee_name = String::new();
1084
1085 if func.kind() == "navigation_expression" {
1086 // property = property/field fields (null) → namedChild(1), with
1087 // the navigation_suffix simple_identifier unwrap.
1088 let property = func
1089 .child_by_field_name("property")
1090 .or_else(|| func.child_by_field_name("field"))
1091 .or_else(|| {
1092 let c1 = func.named_child(1);
1093 match c1 {
1094 Some(c) if c.kind() == "navigation_suffix" => (0..c.named_child_count())
1095 .filter_map(|i| c.named_child(i))
1096 .find(|g| g.kind() == "simple_identifier")
1097 .or(Some(c)),
1098 other => other,
1099 }
1100 });
1101 if let Some(property) = property {
1102 let method_name = self.text(property);
1103 // Through a prefix operator, `try` and `await`:
1104 // `(!store).contains(x)`, `(try! A()).b()`.
1105 let receiver = func
1106 .child_by_field_name("object")
1107 .or_else(|| func.child_by_field_name("operand"))
1108 .or_else(|| func.child_by_field_name("argument"))
1109 .or_else(|| func.named_child(0))
1110 .map(|r| peel_call_wrappers(r, self.src));
1111 if let Some(r) = receiver {
1112 if is_literal_receiver(r.kind()) {
1113 return; // `"lit".upper()` / `5.times()` — nothing
1114 }
1115 }
1116 let recv_ident = receiver.filter(|r| {
1117 matches!(r.kind(), "identifier" | "simple_identifier" | "field_identifier")
1118 });
1119 if let Some(r) = recv_ident {
1120 let receiver_name = self.text(r);
1121 if matches!(receiver_name, "self" | "this" | "cls" | "super") {
1122 callee_name = method_name.to_string();
1123 } else {
1124 callee_name = format!("{receiver_name}.{method_name}");

Callers 2

visit_nodeMethod · 0.45

Calls 12

peel_call_wrappersFunction · 0.85
unwrapped_textFunction · 0.85
is_type_pathFunction · 0.85
edge_kind_indexFunction · 0.85
mapMethod · 0.80
is_literal_receiverFunction · 0.70
strip_js_wsFunction · 0.70
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
firstMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected