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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

1304 // --- function-as-value refs (SWIFT_SPEC, function-ref.ts:288) -------------------
1305
1306 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1307 enum Mode {
1308 Args,
1309 Rhs,
1310 List,
1311 Varinit,
1312 }
1313 let mode = match node.kind() {
1314 "value_arguments" => Mode::Args,
1315 "assignment" => Mode::Rhs, // field 'result'
1316 "array_literal" => Mode::List,
1317 "property_declaration" => Mode::Varinit, // field 'value'
1318 _ => return,
1319 };
1320 if self.stack.is_empty() {
1321 return;
1322 }
1323 let from = self.top_row();
1324
1325 let mut values: Vec<Node> = Vec::new();
1326 match mode {
1327 Mode::Args | Mode::List => {
1328 for c in node.named_children(&mut node.walk()) {
1329 values.push(c);
1330 }
1331 }
1332 Mode::Rhs => {
1333 if let Some(rhs) = node.child_by_field_name("result") {
1334 // Param-storage skip — swift's LHS field is `target`.
1335 let lhs = node
1336 .child_by_field_name("left")
1337 .or_else(|| node.child_by_field_name("lhs"))
1338 .or_else(|| node.child_by_field_name("target"))
1339 .or_else(|| {
1340 if node.named_child_count() >= 2 { node.named_child(0) } else { None }
1341 });
1342 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1343 let lhs_last = util::lhs_last_name()
1344 .captures(lhs_text)
1345 .and_then(|c| c.get(1))
1346 .map(|m| m.as_str());
1347 let rhs_text = self.text(rhs).trim();
1348 if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) {
1349 values.push(rhs);
1350 }
1351 }
1352 }
1353 Mode::Varinit => {
1354 // Destructuring gate: swift's name field is a `pattern` node —
1355 // never in the pattern-kind set → never skipped.
1356 let name_child = node
1357 .child_by_field_name("name")
1358 .or_else(|| node.child_by_field_name("pattern"));
1359 let is_destructuring = name_child
1360 .map(|nc| {
1361 matches!(
1362 nc.kind(),
1363 "object_pattern" | "array_pattern" | "tuple_pattern" | "struct_pattern"

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected