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

Method maybe_capture_fn_refs

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

1375 /// No layers/unwrap/special — only bare identifiers qualify (`&handler`
1376 /// captures nothing). QUIRK: const_item is NOT in the dispatch.
1377 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1378 enum Mode {
1379 Args,
1380 Rhs,
1381 Value,
1382 List,
1383 Varinit,
1384 }
1385 let mode = match node.kind() {
1386 "arguments" => Mode::Args,
1387 "assignment_expression" => Mode::Rhs,
1388 "field_initializer" => Mode::Value,
1389 "array_expression" => Mode::List,
1390 "static_item" | "let_declaration" => Mode::Varinit,
1391 _ => return,
1392 };
1393 if self.stack.is_empty() {
1394 return;
1395 }
1396 let from = self.top_row();
1397
1398 let mut values: Vec<Node> = Vec::new();
1399 match mode {
1400 Mode::Args | Mode::List => {
1401 for c in node.named_children(&mut node.walk()) {
1402 values.push(c);
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 }
1433 Mode::Varinit => {
1434 // Destructuring skip: a tuple/struct pattern LHS extracts data,

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 10

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
walkMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected