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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected