3
3
4
4
import networkx as nx
5
5
6
- from automata .tools .search .local_types import File , Symbol , SymbolReference
6
+ from automata .tools .search .local_types import File , StrPath , Symbol , SymbolReference
7
7
from automata .tools .search .scip_pb2 import Index , SymbolRole
8
8
from automata .tools .search .symbol_converter import SymbolConverter
9
9
from automata .tools .search .symbol_parser import parse_uri_to_symbol
13
13
14
14
class SymbolGraph :
15
15
def __init__ (
16
- self , index_path : str , symbol_converter : SymbolConverter , do_shortened_symbols : bool = True
16
+ self ,
17
+ index_path : StrPath ,
18
+ symbol_converter : SymbolConverter ,
19
+ do_shortened_symbols : bool = True ,
17
20
):
18
21
"""
19
22
Initialize SymbolGraph with the path of an index protobuf file.
@@ -33,7 +36,11 @@ def get_all_files(self) -> List[File]:
33
36
34
37
:return: List of all file nodes.
35
38
"""
36
- return [data for _ , data in self ._graph .nodes (data = True ) if data .get ("label" ) == "file" ]
39
+ return [
40
+ data .get ("file" )
41
+ for _ , data in self ._graph .nodes (data = True )
42
+ if data .get ("label" ) == "file"
43
+ ]
37
44
38
45
def get_all_defined_symbols (self ) -> List [Symbol ]:
39
46
"""
@@ -54,9 +61,9 @@ def get_symbol_references(self, symbol: Symbol) -> Dict[str, List[SymbolReferenc
54
61
:return: List of tuples (file, symbol details)
55
62
"""
56
63
search_results = [
57
- (file_path , symbol_reference )
58
- for file_path , symbol_reference , label in self ._graph .out_edges (symbol , data = True )
59
- if label == "reference"
64
+ (file_path , data . get ( " symbol_reference" ) )
65
+ for file_path , _ , data in self ._graph .out_edges (symbol , data = True )
66
+ if data . get ( " label" ) == "reference"
60
67
]
61
68
result_dict : Dict [str , List [SymbolReference ]] = {}
62
69
@@ -141,11 +148,12 @@ def _build_symbol_graph(self, index: Index) -> nx.MultiDiGraph:
141
148
G = nx .MultiDiGraph ()
142
149
for document in index .documents :
143
150
# Add File Vertices
144
- document_path = document .relative_path
151
+ document_path : StrPath = document .relative_path
152
+
145
153
G .add_node (
146
154
document_path ,
147
155
file = File (path = document .relative_path , occurrences = document .occurrences ),
148
- label = "file_path " ,
156
+ label = "file " ,
149
157
)
150
158
151
159
for symbol_information in document .symbols :
@@ -167,6 +175,7 @@ def _build_symbol_graph(self, index: Index) -> nx.MultiDiGraph:
167
175
occurrence_range = tuple (occurrence_information .range )
168
176
occurrence_roles = self ._get_symbol_roles_dict (occurrence_information .symbol_roles )
169
177
occurrence_reference = SymbolReference (
178
+ symbol = occurrence_symbol ,
170
179
line_number = occurrence_range [0 ],
171
180
roles = occurrence_roles ,
172
181
)
@@ -195,7 +204,7 @@ def _get_symbol_roles_dict(role) -> Dict[str, bool]:
195
204
return result
196
205
197
206
@staticmethod
198
- def _load_index_protobuf (path : str ) -> Index :
207
+ def _load_index_protobuf (path : StrPath ) -> Index :
199
208
"""
200
209
Load an index from a protobuf file.
201
210
0 commit comments