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

Method try_visit_hook

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

Source from the content-addressed store, hash-verified

479 // --- the visitNode hook (php.ts:108) ------------------------------------------
480
481 fn try_visit_hook(&mut self, node: Node<'t>) -> bool {
482 match node.kind() {
483 // Class/interface/trait/enum/top-level constants: one `constant`
484 // node per const_element, NO extras, values never walked.
485 "const_declaration" => {
486 let elements: Vec<Node> = (0..node.named_child_count())
487 .filter_map(|i| node.named_child(i))
488 .filter(|c| c.kind() == "const_element")
489 .collect();
490 for elem in elements {
491 let name_node = (0..elem.named_child_count())
492 .filter_map(|i| elem.named_child(i))
493 .find(|c| c.kind() == "name");
494 let Some(name_node) = name_node else { continue };
495 let name = self.text(name_node).to_string();
496 self.create_node("constant", &name, elem, Extra::default());
497 }
498 true
499 }
500 // Trait use inside a class-like body: one `implements` ref per
501 // used name (full qualified text), all at the use_declaration's
502 // position — WITH filePath (the hook sets ctx.filePath; v2 flag).
503 "use_declaration" => {
504 let names: Vec<Node> = (0..node.named_child_count())
505 .filter_map(|i| node.named_child(i))
506 .filter(|c| matches!(c.kind(), "name" | "qualified_name"))
507 .collect();
508 let parent = self.top_row();
509 let implements = edge_kind_index("implements").unwrap();
510 let line = self.line_of(node);
511 let col = self.col_of(node);
512 for n in names {
513 let name_ref = self.arena.put(self.text(n));
514 self.tables.push_ref_flagged(
515 &RefRow {
516 from_idx: parent,
517 kind: implements,
518 line,
519 column: col,
520 reference_name: name_ref,
521 candidates: NONE_STR,
522 from_id_str: NONE_STR,
523 },
524 REF_FLAG_FILE_PATH,
525 );
526 }
527 true
528 }
529 _ => false,
530 }
531 }
532
533 // --- the dispatcher (visitNode, PHP-relevant branches) ------------------------
534

Callers 1

visit_nodeMethod · 0.45

Calls 10

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

Tested by

no test coverage detected