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

Method maybe_capture_fn_refs

codegraph-kernel/src/csharp.rs:1280–1360  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1278 // --- function-as-value refs (CSHARP_SPEC, function-ref.ts:250) --------------
1279
1280 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1281 #[derive(PartialEq)]
1282 enum Mode {
1283 Args,
1284 Rhs,
1285 List,
1286 Varinit,
1287 }
1288 let mode = match node.kind() {
1289 "argument_list" => Mode::Args,
1290 "assignment_expression" => Mode::Rhs, // covers `+=` event subscription
1291 "initializer_expression" => Mode::List,
1292 "variable_declarator" => Mode::Varinit,
1293 _ => return,
1294 };
1295 if self.stack.is_empty() {
1296 return;
1297 }
1298 let from = self.top_row();
1299
1300 let mut values: Vec<Node> = Vec::new();
1301 match mode {
1302 Mode::Args | Mode::List => {
1303 for i in 0..node.named_child_count() {
1304 if let Some(c) = node.named_child(i) {
1305 values.push(c);
1306 }
1307 }
1308 }
1309 Mode::Rhs => {
1310 if let Some(rhs) = node.child_by_field_name("right") {
1311 // Param-storage skip: `this.status = status`.
1312 let lhs = node
1313 .child_by_field_name("left")
1314 .or_else(|| node.child_by_field_name("lhs"))
1315 .or_else(|| node.child_by_field_name("target"))
1316 .or_else(|| {
1317 if node.named_child_count() >= 2 { node.named_child(0) } else { None }
1318 });
1319 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1320 let lhs_last = util::lhs_last_name()
1321 .captures(lhs_text)
1322 .and_then(|c| c.get(1))
1323 .map(|m| m.as_str());
1324 let rhs_text = self.text(rhs).trim();
1325 if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) {
1326 values.push(rhs);
1327 }
1328 }
1329 }
1330 Mode::Varinit => {
1331 // No `value` field on C# variable_declarator: the initializer
1332 // is the LAST named child — but an initializer-less declarator
1333 // has its NAME there. Require ≥2 named children and never pick
1334 // the name child. (Destructuring pattern gate never matches C#.)
1335 let name_child = node
1336 .child_by_field_name("name")
1337 .or_else(|| node.child_by_field_name("pattern"));

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

getMethod · 0.65
top_rowMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected