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

Method extract_call

codegraph-kernel/src/csharp.rs:1141–1202  ·  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

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

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