@@ -39,16 +39,34 @@ def supported_types(self) -> list[str]:
3939 """
4040 return list (analyzers .keys ())
4141
42- def create_hierarchy (self , analyzer : AbstractAnalyzer , file : File ):
43- types = analyzer .get_top_level_entity_types ()
42+ def create_entity_hierarchy (self , entity : Entity , file : File , analyzer : AbstractAnalyzer , graph : Graph ):
43+ types = analyzer .get_entity_types ()
44+ stack = list (entity .node .children )
45+ while stack :
46+ node = stack .pop ()
47+ if node .type in types :
48+ child = Entity (node )
49+ child .id = graph .add_entity (analyzer .get_entity_label (node ), analyzer .get_entity_name (node ), analyzer .get_entity_docstring (node ), str (file .path ), node .start_point .row , node .end_point .row , {})
50+ analyzer .add_symbols (child )
51+ file .add_entity (entity )
52+ entity .add_child (child )
53+ graph .connect_entities ("DEFINES" , entity .id , child .id )
54+ self .create_entity_hierarchy (child , file , analyzer , graph )
55+ else :
56+ stack .extend (node .children )
57+
58+ def create_hierarchy (self , file : File , analyzer : AbstractAnalyzer , graph : Graph ):
59+ types = analyzer .get_entity_types ()
4460 stack = [file .tree .root_node ]
4561 while stack :
4662 node = stack .pop ()
4763 if node .type in types :
4864 entity = Entity (node )
65+ entity .id = graph .add_entity (analyzer .get_entity_label (node ), analyzer .get_entity_name (node ), analyzer .get_entity_docstring (node ), str (file .path ), node .start_point .row , node .end_point .row , {})
4966 analyzer .add_symbols (entity )
50- analyzer .add_children (entity )
5167 file .add_entity (entity )
68+ graph .connect_entities ("DEFINES" , file .id , entity .id )
69+ self .create_entity_hierarchy (entity , file , analyzer , graph )
5270 else :
5371 stack .extend (node .children )
5472
@@ -85,15 +103,8 @@ def first_pass(self, path: Path, ignore: list[str], graph: Graph) -> None:
85103 self .files [file_path ] = file
86104
87105 # Walk thought the AST
88- self .create_hierarchy (analyzer , file )
89-
90106 graph .add_file (file )
91- for node , entity in file .entities .items ():
92- entity .id = graph .add_entity (analyzer .get_entity_label (node ), analyzer .get_entity_name (node ), analyzer .get_entity_docstring (node ), str (file_path ), node .start_point .row , node .end_point .row , {})
93- graph .connect_entities ("DEFINES" , file .id , entity .id )
94- for child_node , child_entity in entity .children .items ():
95- child_entity .id = graph .add_entity (analyzer .get_entity_label (child_node ), analyzer .get_entity_name (child_node ), analyzer .get_entity_docstring (child_node ), str (file_path ), child_node .start_point .row , child_node .end_point .row , {"src" : child_node .text .decode ("utf-8" )})
96- graph .connect_entities ("DEFINES" , entity .id , child_entity .id )
107+ self .create_hierarchy (file , analyzer , graph )
97108
98109 def second_pass (self , graph : Graph , path : Path ) -> None :
99110 """
0 commit comments