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

Method try_visit_hook

codegraph-kernel/src/ruby.rs:441–503  ·  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

439 /// the source of the module multiply-capture quirk (scan runs with the
440 /// module already POPPED, so candidates re-attribute to the outer scope).
441 fn try_visit_hook(&mut self, node: Node<'t>) -> bool {
442 stack_guard!();
443 let kind = node.kind();
444 if kind == "call" && node.child_by_field_name("receiver").is_none() {
445 if let Some(method) = node.child_by_field_name("method") {
446 if matches!(self.text(method), "include" | "extend" | "prepend") {
447 let args = node.child_by_field_name("arguments").or_else(|| {
448 (0..node.named_child_count())
449 .filter_map(|i| node.named_child(i))
450 .find(|c| c.kind() == "argument_list")
451 });
452 // (nodeStack is never empty — the file node is pushed.)
453 if let Some(args) = args {
454 let parent = self.top_row();
455 let implements = edge_kind_index("implements").unwrap();
456 let line = self.line_of(node);
457 let col = self.col_of(node);
458 for arg in args.named_children(&mut args.walk()) {
459 // `Mod` is constant, `Foo::Bar` is scope_resolution;
460 // `extend self` / dynamic args are skipped. Unlike
461 // every other extraction ref, the hook sets
462 // `filePath: ctx.filePath` — flagged on the wire.
463 if matches!(arg.kind(), "constant" | "scope_resolution") {
464 let name_ref = self.arena.put(self.text(arg));
465 self.tables.push_ref_flagged(
466 &RefRow {
467 from_idx: parent,
468 kind: implements,
469 line,
470 column: col,
471 reference_name: name_ref,
472 candidates: NONE_STR,
473 from_id_str: NONE_STR,
474 },
475 REF_FLAG_FILE_PATH,
476 );
477 }
478 }
479 return true;
480 }
481 // no args node → hook declines (falls to extractImport → nothing)
482 }
483 }
484 }
485
486 if kind != "module" {
487 return false;
488 }
489 let Some(name_node) = node.child_by_field_name("name") else { return false };
490 // `module A::B` keeps the scope_resolution text verbatim as the name.
491 let name = self.text(name_node).to_string();
492 let Some(row) = self.create_node("module", &name, node, Extra::default()) else {
493 return false;
494 };
495 self.stack.push(Scope { row, kind: "module", name });
496 if let Some(body) = node.child_by_field_name("body") {
497 for c in body.named_children(&mut body.walk()) {
498 self.visit_node(c);

Callers 1

visit_nodeMethod · 0.45

Calls 12

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
walkMethod · 0.45
create_nodeMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected