11
11
from .model .cache import Cache
12
12
from .model .cmakefiles import CMakeFiles
13
13
from .model .codemodel import CodeModel , Target
14
+ from .model .codemodel import Directory as CodeModelDirectory
15
+ from .model .directory import Directory
14
16
from .model .index import Index , Reply
15
17
16
18
T = TypeVar ("T" )
@@ -37,16 +39,21 @@ def make_converter(base_dir: Path) -> cattr.preconf.json.JsonConverter:
37
39
converter .register_structure_hook (Reply , st_hook )
38
40
39
41
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 )
40
44
if with_path ["jsonFile" ] is None :
41
45
return converter .structure_attrs_fromdict ({}, t )
42
46
path = base_dir / Path (with_path ["jsonFile" ])
43
47
raw = json .loads (path .read_text (encoding = "utf-8" ))
48
+ if t is CodeModelDirectory :
49
+ t = Directory # type: ignore[assignment]
44
50
return converter .structure_attrs_fromdict (raw , t )
45
51
46
52
converter .register_structure_hook (CodeModel , from_json_file )
47
53
converter .register_structure_hook (Target , from_json_file )
48
54
converter .register_structure_hook (Cache , from_json_file )
49
55
converter .register_structure_hook (CMakeFiles , from_json_file )
56
+ converter .register_structure_hook (CodeModelDirectory , from_json_file )
50
57
return converter
51
58
52
59
0 commit comments