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

Method try_visit_hook

codegraph-kernel/src/ruby.rs:411–476  ·  view source on GitHub ↗

Returns true when the hook handled the node (mixin call or module). The DISPATCHER then runs scan_fn_ref_subtree on the handled subtree — the source of the module multiply-capture quirk (scan runs with the module already POPPED, so candidates re-attribute to the outer scope).

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

409 /// the source of the module multiply-capture quirk (scan runs with the
410 /// module already POPPED, so candidates re-attribute to the outer scope).
411 fn try_visit_hook(&mut self, node: Node<'t>) -> bool {
412 stack_guard!();
413 let kind = node.kind();
414 if kind == "call" && node.child_by_field_name("receiver").is_none() {
415 if let Some(method) = node.child_by_field_name("method") {
416 if matches!(self.text(method), "include" | "extend" | "prepend") {
417 let args = node.child_by_field_name("arguments").or_else(|| {
418 (0..node.named_child_count())
419 .filter_map(|i| node.named_child(i))
420 .find(|c| c.kind() == "argument_list")
421 });
422 // (nodeStack is never empty — the file node is pushed.)
423 if let Some(args) = args {
424 let parent = self.top_row();
425 let implements = edge_kind_index("implements").unwrap();
426 let line = self.line_of(node);
427 let col = self.col_of(node);
428 for i in 0..args.named_child_count() {
429 let Some(arg) = args.named_child(i) else { continue };
430 // `Mod` is constant, `Foo::Bar` is scope_resolution;
431 // `extend self` / dynamic args are skipped. Unlike
432 // every other extraction ref, the hook sets
433 // `filePath: ctx.filePath` — flagged on the wire.
434 if matches!(arg.kind(), "constant" | "scope_resolution") {
435 let name_ref = self.arena.put(self.text(arg));
436 self.tables.push_ref_flagged(
437 &RefRow {
438 from_idx: parent,
439 kind: implements,
440 line,
441 column: col,
442 reference_name: name_ref,
443 candidates: NONE_STR,
444 from_id_str: NONE_STR,
445 },
446 REF_FLAG_FILE_PATH,
447 );
448 }
449 }
450 return true;
451 }
452 // no args node → hook declines (falls to extractImport → nothing)
453 }
454 }
455 }
456
457 if kind != "module" {
458 return false;
459 }
460 let Some(name_node) = node.child_by_field_name("name") else { return false };
461 // `module A::B` keeps the scope_resolution text verbatim as the name.
462 let name = self.text(name_node).to_string();
463 let Some(row) = self.create_node("module", &name, node, Extra::default()) else {
464 return false;
465 };
466 self.stack.push(Scope { row, kind: "module", name });
467 if let Some(body) = node.child_by_field_name("body") {
468 for i in 0..body.named_child_count() {

Callers 1

visit_nodeMethod · 0.45

Calls 11

edge_kind_indexFunction · 0.85
push_ref_flaggedMethod · 0.80
pushMethod · 0.80
putMethod · 0.65
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
line_ofMethod · 0.45
col_ofMethod · 0.45
create_nodeMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected