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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

1350 // --- function-as-value refs (SWIFT_SPEC, function-ref.ts:288) -------------------
1351
1352 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1353 enum Mode {
1354 Args,
1355 Rhs,
1356 List,
1357 Varinit,
1358 }
1359 let mode = match node.kind() {
1360 "value_arguments" => Mode::Args,
1361 "assignment" => Mode::Rhs, // field 'result'
1362 "array_literal" => Mode::List,
1363 "property_declaration" => Mode::Varinit, // field 'value'
1364 _ => return,
1365 };
1366 if self.stack.is_empty() {
1367 return;
1368 }
1369 let from = self.top_row();
1370
1371 let mut values: Vec<Node> = Vec::new();
1372 match mode {
1373 Mode::Args | Mode::List => {
1374 for i in 0..node.named_child_count() {
1375 if let Some(c) = node.named_child(i) {
1376 values.push(c);
1377 }
1378 }
1379 }
1380 Mode::Rhs => {
1381 if let Some(rhs) = node.child_by_field_name("result") {
1382 // Param-storage skip — swift's LHS field is `target`.
1383 let lhs = node
1384 .child_by_field_name("left")
1385 .or_else(|| node.child_by_field_name("lhs"))
1386 .or_else(|| node.child_by_field_name("target"))
1387 .or_else(|| {
1388 if node.named_child_count() >= 2 { node.named_child(0) } else { None }
1389 });
1390 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1391 let lhs_last = util::lhs_last_name()
1392 .captures(lhs_text)
1393 .and_then(|c| c.get(1))
1394 .map(|m| m.as_str());
1395 let rhs_text = self.text(rhs).trim();
1396 if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) {
1397 values.push(rhs);
1398 }
1399 }
1400 }
1401 Mode::Varinit => {
1402 // Destructuring gate: swift's name field is a `pattern` node —
1403 // never in the pattern-kind set → never skipped.
1404 let name_child = node
1405 .child_by_field_name("name")
1406 .or_else(|| node.child_by_field_name("pattern"));
1407 let is_destructuring = name_child
1408 .map(|nc| {
1409 matches!(

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 6

pushMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected