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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

Callers 3

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