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

Method visit

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

Source from the content-addressed store, hash-verified

816 // --- the main walk (visitNode, tree-sitter.ts:936-1303) ---------------
817
818 fn visit(&mut self, node: Node<'t>) {
819 stack_guard!();
820 // The visitNode hook (dart.ts:144-157) — the constants branch.
821 if node.kind() == "static_final_declaration" {
822 let mut cursor = node.walk();
823 let name_node = node.named_children(&mut cursor).find(|c| c.kind() == "identifier");
824 if let Some(name_node) = name_node {
825 // signature = first value sibling's text, sliced to 100
826 // UTF-16 units (a flattened chain captures just its head).
827 let signature = name_node.next_named_sibling().map(|v| util::init_signature(self.text(v)));
828 let name = self.text(name_node).to_string();
829 let constant = self.create_node("constant", &name, node, Extra { signature, ..Default::default() });
830 // The initializer is code the constant runs — its calls,
831 // instantiations, reads and the types it names (#2327) are
832 // the constant's. walkInitializer: the body walk, and the
833 // dispatcher's fn-ref scan skips what it walked.
834 if let Some(constant) = constant {
835 self.stack.push(Scope { row: constant, kind: "constant", name });
836 self.visit_body(node);
837 self.stack.pop();
838 return;
839 }
840 }
841 self.scan_fn_ref_subtree(node, 0);
842 return;
843 }
844
845 // A field's or top-level variable's initializer is code its class or
846 // the file runs (neither mints a node) — the hook's
847 // `initialized_identifier` row, walked like a body (walkInitializer).
848 if node.kind() == "initialized_identifier" && self.is_field_or_top_level_entry(node) {
849 self.visit_body(node);
850 return;
851 }
852
853 // A field's declared type is its class's (Dart fields mint no nodes);
854 // a top-level variable's is the file's (#2327). The visitNode hook's
855 // `declaration` / `program` rows (dart.ts). (Parent lookups walk down
856 // from the root, so only the node kinds that can be these positions
857 // ask for theirs.)
858 if node.kind() == "declaration" {
859 let in_body = node
860 .parent()
861 .map(|p| matches!(p.kind(), "class_body" | "extension_body" | "enum_body"))
862 .unwrap_or(false);
863 let mut cursor = node.walk();
864 let kids: Vec<Node<'t>> = node.named_children(&mut cursor).collect();
865 let is_field = in_body
866 && kids
867 .iter()
868 .any(|c| matches!(c.kind(), "initialized_identifier_list" | "static_final_declaration_list"));
869 if is_field {
870 let owner = self.top_row();
871 for child in kids {
872 if !matches!(child.kind(), "initialized_identifier_list" | "static_final_declaration_list") {
873 self.type_refs_dart(child, owner);
874 }
875 }

Callers 3

extractFunction · 0.45
extract_classMethod · 0.45
extract_enumMethod · 0.45

Calls 15

init_signatureFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
type_refs_dartMethod · 0.80
textMethod · 0.65
walkMethod · 0.45
create_nodeMethod · 0.45
visit_bodyMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45
collectMethod · 0.45
top_rowMethod · 0.45

Tested by

no test coverage detected