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

Method maybe_capture_fn_refs

codegraph-kernel/src/scala.rs:1229–1295  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1227 // --- function-as-value capture (#756) — SCALA_SPEC --------------------
1228
1229 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1230 let (mode, field): (&str, &str) = match node.kind() {
1231 "arguments" => ("args", ""),
1232 "assignment_expression" => ("rhs", "right"),
1233 "val_definition" => ("varinit", "value"),
1234 _ => return,
1235 };
1236 if self.stack.is_empty() {
1237 return;
1238 }
1239 let from = self.top_row();
1240
1241 let mut values: Vec<Node<'t>> = Vec::new();
1242 match mode {
1243 "args" => {
1244 let mut cursor = node.walk();
1245 for c in node.named_children(&mut cursor) {
1246 values.push(c);
1247 }
1248 }
1249 "rhs" => {
1250 if let Some(rhs) = node.child_by_field_name(field) {
1251 // Param-storage skip: lhs tail == rhs text.
1252 let lhs = node
1253 .child_by_field_name("left")
1254 .or_else(|| node.child_by_field_name("lhs"))
1255 .or_else(|| node.child_by_field_name("target"))
1256 .or_else(|| {
1257 if node.named_child_count() >= 2 {
1258 node.named_child(0)
1259 } else {
1260 None
1261 }
1262 });
1263 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1264 let lhs_last = util::lhs_last_name()
1265 .captures(lhs_text)
1266 .and_then(|c| c.get(1))
1267 .map(|m| m.as_str());
1268 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1269 values.push(rhs);
1270 }
1271 }
1272 }
1273 _ => {
1274 // varinit — destructuring patterns capture nothing.
1275 let name_node = node
1276 .child_by_field_name("name")
1277 .or_else(|| node.child_by_field_name("pattern"));
1278 if let Some(nn) = name_node {
1279 if matches!(
1280 nn.kind(),
1281 "object_pattern" | "array_pattern" | "tuple_pattern" | "struct_pattern"
1282 ) {
1283 return;
1284 }
1285 }
1286 if let Some(v) = node.child_by_field_name(field) {

Callers 3

visitMethod · 0.45
visit_bodyMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 7

walkMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected