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

Method extract_call

codegraph-kernel/src/csharp.rs:1122–1183  ·  view source on GitHub ↗

extractCall — the C# branch (tree-sitter.ts:4502) + shared tail.

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

Source from the content-addressed store, hash-verified

1120
1121 /// extractCall — the C# branch (tree-sitter.ts:4502) + shared tail.
1122 fn extract_call(&mut self, node: Node<'t>) {
1123 if self.stack.is_empty() {
1124 return;
1125 }
1126 let caller = self.top_row();
1127 let func = node
1128 .child_by_field_name("function")
1129 .or_else(|| node.named_child(0));
1130 let Some(func) = func else { return };
1131
1132 let mut callee_name: String;
1133 if func.kind() == "member_access_expression" {
1134 let recv = func.child_by_field_name("expression");
1135 let name_node = func.child_by_field_name("name");
1136 let method_name = name_node.map(|n| self.text(n)).unwrap_or("");
1137 let chained = recv
1138 .map(|r| r.kind() == "invocation_expression" && !method_name.is_empty())
1139 .unwrap_or(false);
1140 if chained {
1141 // Chained factory `Foo.Create(args).Bar()` → `Foo.Create().Bar`
1142 // (inner whitespace stripped, EVERY call-receiver re-encodes —
1143 // no capitalization gate, unlike kotlin/scala).
1144 let inner_func = recv.unwrap().child_by_field_name("function");
1145 let inner_callee = inner_func.map(|f| strip_js_ws(self.text(f))).unwrap_or_default();
1146 callee_name = if inner_callee.is_empty() {
1147 method_name.to_string()
1148 } else {
1149 format!("{inner_callee}().{method_name}")
1150 };
1151 } else {
1152 // RAW full member-access text: `this.Run`, `base.Method`,
1153 // `"lit".ToUpper`, multi-line fluent chains with their
1154 // newlines — no SKIP_RECEIVERS, no literal filter (preserve).
1155 callee_name = self.text(func).to_string();
1156 }
1157 } else {
1158 // Bare `Helper()`, generic `Generic<int>` kept verbatim,
1159 // `nameof(...)` → a calls ref named `nameof`, `?.` chains raw,
1160 // `(myDel)(x)` → parenthesized text (normalized below).
1161 callee_name = self.text(func).to_string();
1162 }
1163
1164 // Null-conditional / null-forgiving receivers spelled with plain dots
1165 // (#2906): `_maybe?.Send` / `_maybe!.Send` → `_maybe.Send`. Mirrors
1166 // extractCall's `/[?!]\./g` (tree-sitter.ts): leftmost, non-overlapping.
1167 if callee_name.contains("?.") || callee_name.contains("!.") {
1168 callee_name = null_receiver_re().replace_all(&callee_name, ".").into_owned();
1169 }
1170
1171 // Shared parenthesized-conversion normalization — the one shared
1172 // normalization C# actually hits: `(myDel)(x)` → `myDel`.
1173 if !callee_name.is_empty() {
1174 if let Some(c) = util::paren_conversion().captures(&callee_name) {
1175 callee_name = c[1].to_string();
1176 }
1177 }
1178 // (template strip + fn-ptr fan-out are c/cpp-gated — not C#.)
1179

Callers 2

visit_nodeMethod · 0.45

Calls 8

null_receiver_reFunction · 0.85
edge_kind_indexFunction · 0.85
mapMethod · 0.80
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