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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

getMethod · 0.65
top_rowMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected