1111from .model .cache import Cache
1212from .model .cmakefiles import CMakeFiles
1313from .model .codemodel import CodeModel , Target
14+ from .model .codemodel import Directory as CodeModelDirectory
15+ from .model .directory import Directory
1416from .model .index import Index , Reply
1517
1618T = TypeVar ("T" )
@@ -37,16 +39,21 @@ def make_converter(base_dir: Path) -> cattr.preconf.json.JsonConverter:
3739 converter .register_structure_hook (Reply , st_hook )
3840
3941 def from_json_file (with_path : Dict [str , Any ], t : Type [T ]) -> T :
42+ if "jsonFile" not in with_path and t is CodeModelDirectory :
43+ return converter .structure_attrs_fromdict (with_path , t )
4044 if with_path ["jsonFile" ] is None :
4145 return converter .structure_attrs_fromdict ({}, t )
4246 path = base_dir / Path (with_path ["jsonFile" ])
4347 raw = json .loads (path .read_text (encoding = "utf-8" ))
48+ if t is CodeModelDirectory :
49+ t = Directory # type: ignore[assignment]
4450 return converter .structure_attrs_fromdict (raw , t )
4551
4652 converter .register_structure_hook (CodeModel , from_json_file )
4753 converter .register_structure_hook (Target , from_json_file )
4854 converter .register_structure_hook (Cache , from_json_file )
4955 converter .register_structure_hook (CMakeFiles , from_json_file )
56+ converter .register_structure_hook (CodeModelDirectory , from_json_file )
5057 return converter
5158
5259
0 commit comments