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

Method maybe_capture_fn_refs

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

1183 /// No layers/unwrap/special — only bare identifiers qualify (`&handler`
1184 /// captures nothing). QUIRK: const_item is NOT in the dispatch.
1185 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1186 enum Mode {
1187 Args,
1188 Rhs,
1189 Value,
1190 List,
1191 Varinit,
1192 }
1193 let mode = match node.kind() {
1194 "arguments" => Mode::Args,
1195 "assignment_expression" => Mode::Rhs,
1196 "field_initializer" => Mode::Value,
1197 "array_expression" => Mode::List,
1198 "static_item" | "let_declaration" => Mode::Varinit,
1199 _ => return,
1200 };
1201 if self.stack.is_empty() {
1202 return;
1203 }
1204 let from = self.top_row();
1205
1206 let mut values: Vec<Node> = Vec::new();
1207 match mode {
1208 Mode::Args | Mode::List => {
1209 for i in 0..node.named_child_count() {
1210 if let Some(c) = node.named_child(i) {
1211 values.push(c);
1212 }
1213 }
1214 }
1215 Mode::Rhs => {
1216 if let Some(rhs) = node.child_by_field_name("right") {
1217 // Param-storage skip: `o.cb = cb`.
1218 let lhs_text = node
1219 .child_by_field_name("left")
1220 .map(|l| self.text(l))
1221 .unwrap_or("");
1222 let lhs_last = util::lhs_last_name()
1223 .captures(lhs_text)
1224 .and_then(|c| c.get(1))
1225 .map(|m| m.as_str());
1226 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1227 values.push(rhs);
1228 }
1229 }
1230 }
1231 Mode::Value => {
1232 let v = node.child_by_field_name("value").or_else(|| {
1233 if node.named_child_count() > 0 {
1234 node.named_child(node.named_child_count() - 1)
1235 } else {
1236 None
1237 }
1238 });
1239 if let Some(v) = v {
1240 values.push(v);
1241 }
1242 }

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

is_stoplistedFunction · 0.70
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected