Skip to content

Commit bed09f2

Browse files
committed
Refactor import handling in CodeBase to prioritize definition_id for cached elements and streamline unique_id assignment
1 parent 89264e5 commit bed09f2

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

codetide/core/models.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,14 @@ def _build_cached_elements(self, force_update :bool=False):
427427
### DO IMPORT LATER
428428
for codeFile in self.root:
429429
for unique_id, element in codeFile.all_imports(as_dict=True).items():
430-
if unique_id in self._cached_elements:
430+
### TODO double check this later with tests
431+
if element.definition_id and element.definition_id in self._cached_elements:
432+
self._cached_elements[unique_id] = self._cached_elements[element.definition_id]
433+
elif unique_id in self._cached_elements:
431434
# print(f"IMPORT {unique_id} already exists")
432435
continue
433-
self._cached_elements[unique_id] = element
436+
else:
437+
self._cached_elements[unique_id] = element
434438

435439

436440
def _list_all_unique_ids_for_property(self, property :Literal["classes", "functions", "variables", "imports"])->List[str]:

0 commit comments

Comments
 (0)