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

Method maybe_capture_fn_refs

codegraph-kernel/src/rustlang.rs:1375–1499  ·  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

1373 /// No layers/unwrap/special — only bare identifiers qualify (`&handler`
1374 /// captures nothing). QUIRK: const_item is NOT in the dispatch.
1375 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1376 enum Mode {
1377 Args,
1378 Rhs,
1379 Value,
1380 List,
1381 Varinit,
1382 }
1383 let mode = match node.kind() {
1384 "arguments" => Mode::Args,
1385 "assignment_expression" => Mode::Rhs,
1386 "field_initializer" => Mode::Value,
1387 "array_expression" => Mode::List,
1388 "static_item" | "let_declaration" => Mode::Varinit,
1389 _ => return,
1390 };
1391 if self.stack.is_empty() {
1392 return;
1393 }
1394 let from = self.top_row();
1395
1396 let mut values: Vec<Node> = Vec::new();
1397 match mode {
1398 Mode::Args | Mode::List => {
1399 for i in 0..node.named_child_count() {
1400 if let Some(c) = node.named_child(i) {
1401 values.push(c);
1402 }
1403 }
1404 }
1405 Mode::Rhs => {
1406 if let Some(rhs) = node.child_by_field_name("right") {
1407 // Param-storage skip: `o.cb = cb`.
1408 let lhs_text = node
1409 .child_by_field_name("left")
1410 .map(|l| self.text(l))
1411 .unwrap_or("");
1412 let lhs_last = util::lhs_last_name()
1413 .captures(lhs_text)
1414 .and_then(|c| c.get(1))
1415 .map(|m| m.as_str());
1416 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1417 values.push(rhs);
1418 }
1419 }
1420 }
1421 Mode::Value => {
1422 let v = node.child_by_field_name("value").or_else(|| {
1423 if node.named_child_count() > 0 {
1424 node.named_child(node.named_child_count() - 1)
1425 } else {
1426 None
1427 }
1428 });
1429 if let Some(v) = v {
1430 values.push(v);
1431 }
1432 }

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 9

is_path_value_textFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80
is_stoplistedFunction · 0.70
is_js_spaceFunction · 0.70
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected