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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

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

Tested by

no test coverage detected