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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

1235 // --- function-as-value refs (KOTLIN_SPEC, function-ref.ts:240) ------------------
1236
1237 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1238 enum Mode {
1239 Args,
1240 Rhs,
1241 }
1242 let mode = match node.kind() {
1243 "value_arguments" => Mode::Args,
1244 "assignment" => Mode::Rhs, // NO field — RHS = LAST named child
1245 _ => return,
1246 };
1247 if self.stack.is_empty() {
1248 return;
1249 }
1250 let from = self.top_row();
1251
1252 let mut values: Vec<Node> = Vec::new();
1253 match mode {
1254 Mode::Args => {
1255 for i in 0..node.named_child_count() {
1256 if let Some(c) = node.named_child(i) {
1257 values.push(c);
1258 }
1259 }
1260 }
1261 Mode::Rhs => {
1262 let rhs = if node.named_child_count() > 0 {
1263 node.named_child(node.named_child_count() - 1)
1264 } else {
1265 None
1266 };
1267 if let Some(rhs) = rhs {
1268 let lhs = node
1269 .child_by_field_name("left")
1270 .or_else(|| node.child_by_field_name("lhs"))
1271 .or_else(|| node.child_by_field_name("target"))
1272 .or_else(|| {
1273 if node.named_child_count() >= 2 { node.named_child(0) } else { None }
1274 });
1275 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1276 let lhs_last = util::lhs_last_name()
1277 .captures(lhs_text)
1278 .and_then(|c| c.get(1))
1279 .map(|m| m.as_str());
1280 let rhs_text = self.text(rhs).trim();
1281 if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) {
1282 values.push(rhs);
1283 }
1284 }
1285 }
1286 }
1287
1288 for v in values {
1289 self.normalize_fn_ref_value(v, from, 0);
1290 }
1291 }
1292
1293 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) {
1294 stack_guard!();

Callers 3

visit_nodeMethod · 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