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

Method maybe_capture_fn_refs

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

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