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

Method visit

codegraph-kernel/src/dart.rs:818–948  ·  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| {
828 let (sliced, _) = util::slice_utf16(self.text(v), 100);
829 if util::utf16_len(&sliced) >= 100 {
830 format!("= {sliced}...")
831 } else {
832 format!("= {sliced}")
833 }
834 });
835 let name = self.text(name_node).to_string();
836 let constant = self.create_node("constant", &name, node, Extra { signature, ..Default::default() });
837 // The initializer is code the constant runs — its calls,
838 // instantiations, reads and the types it names (#2327) are
839 // the constant's. walkInitializer: the body walk, and the
840 // dispatcher's fn-ref scan skips what it walked.
841 if let Some(constant) = constant {
842 self.stack.push(Scope { row: constant, kind: "constant", name });
843 self.visit_body(node);
844 self.stack.pop();
845 return;
846 }
847 }
848 self.scan_fn_ref_subtree(node, 0);
849 return;
850 }
851
852 // A field's or top-level variable's initializer is code its class or
853 // the file runs (neither mints a node) — the hook's
854 // `initialized_identifier` row, walked like a body (walkInitializer).
855 if node.kind() == "initialized_identifier" && self.is_field_or_top_level_entry(node) {
856 self.visit_body(node);
857 return;
858 }
859
860 // A field's declared type is its class's (Dart fields mint no nodes);
861 // a top-level variable's is the file's (#2327). The visitNode hook's
862 // `declaration` / `program` rows (dart.ts). (Parent lookups walk down
863 // from the root, so only the node kinds that can be these positions
864 // ask for theirs.)
865 if node.kind() == "declaration" {
866 let in_body = node
867 .parent()
868 .map(|p| matches!(p.kind(), "class_body" | "extension_body" | "enum_body"))
869 .unwrap_or(false);
870 let mut cursor = node.walk();
871 let kids: Vec<Node<'t>> = node.named_children(&mut cursor).collect();
872 let is_field = in_body
873 && kids
874 .iter()
875 .any(|c| matches!(c.kind(), "initialized_identifier_list" | "static_final_declaration_list"));

Callers 3

extractFunction · 0.45
extract_classMethod · 0.45
extract_enumMethod · 0.45

Calls 15

slice_utf16Function · 0.85
utf16_lenFunction · 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

Tested by

no test coverage detected