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

Method visit

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

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected