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

Method maybe_capture_fn_refs

codegraph-kernel/src/rustlang.rs:1356–1452  ·  view source on GitHub ↗

maybeCaptureFnRefs with RUST_SPEC's dispatch: arguments→args, assignment_expression→rhs(right), field_initializer→value(value), array_expression→list, static_item/let_declaration→varinit(value). No layers/unwrap/special — only bare identifiers qualify (`&handler` captures nothing). QUIRK: const_item is NOT in the dispatch.

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

Source from the content-addressed store, hash-verified

1354 /// No layers/unwrap/special — only bare identifiers qualify (`&handler`
1355 /// captures nothing). QUIRK: const_item is NOT in the dispatch.
1356 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1357 enum Mode {
1358 Args,
1359 Rhs,
1360 Value,
1361 List,
1362 Varinit,
1363 }
1364 let mode = match node.kind() {
1365 "arguments" => Mode::Args,
1366 "assignment_expression" => Mode::Rhs,
1367 "field_initializer" => Mode::Value,
1368 "array_expression" => Mode::List,
1369 "static_item" | "let_declaration" => Mode::Varinit,
1370 _ => return,
1371 };
1372 if self.stack.is_empty() {
1373 return;
1374 }
1375 let from = self.top_row();
1376
1377 let mut values: Vec<Node> = Vec::new();
1378 match mode {
1379 Mode::Args | Mode::List => {
1380 for i in 0..node.named_child_count() {
1381 if let Some(c) = node.named_child(i) {
1382 values.push(c);
1383 }
1384 }
1385 }
1386 Mode::Rhs => {
1387 if let Some(rhs) = node.child_by_field_name("right") {
1388 // Param-storage skip: `o.cb = cb`.
1389 let lhs_text = node
1390 .child_by_field_name("left")
1391 .map(|l| self.text(l))
1392 .unwrap_or("");
1393 let lhs_last = util::lhs_last_name()
1394 .captures(lhs_text)
1395 .and_then(|c| c.get(1))
1396 .map(|m| m.as_str());
1397 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1398 values.push(rhs);
1399 }
1400 }
1401 }
1402 Mode::Value => {
1403 let v = node.child_by_field_name("value").or_else(|| {
1404 if node.named_child_count() > 0 {
1405 node.named_child(node.named_child_count() - 1)
1406 } else {
1407 None
1408 }
1409 });
1410 if let Some(v) = v {
1411 values.push(v);
1412 }
1413 }

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 6

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

Tested by

no test coverage detected