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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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