@@ -466,52 +466,6 @@ and forStructure ~env strItems =
466466 in
467467 {docstring; exported; items}
468468
469- let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos ) =
470- match cmt_annots with
471- | Partial_implementation parts ->
472- let items =
473- parts |> Array. to_list
474- |> Utils. filterMap (fun p ->
475- match (p : Cmt_format.binary_part ) with
476- | Partial_structure str -> Some str.str_items
477- | Partial_structure_item str -> Some [str]
478- | _ -> None )
479- |> List. concat
480- in
481- let env =
482- {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
483- in
484- let structure = forStructure ~env items in
485- {File. uri; moduleName = cmt_modname; stamps = env.stamps; structure}
486- | Partial_interface parts ->
487- let items =
488- parts |> Array. to_list
489- |> Utils. filterMap (fun (p : Cmt_format.binary_part ) ->
490- match p with
491- | Partial_signature str -> Some str.sig_items
492- | Partial_signature_item str -> Some [str]
493- | _ -> None )
494- |> List. concat
495- in
496- let env =
497- {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
498- in
499- let structure = forSignature ~env items in
500- {uri; moduleName = cmt_modname; stamps = env.stamps; structure}
501- | Implementation structure ->
502- let env =
503- {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
504- in
505- let structure = forStructure ~env structure.str_items in
506- {uri; moduleName = cmt_modname; stamps = env.stamps; structure}
507- | Interface signature ->
508- let env =
509- {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
510- in
511- let structure = forSignature ~env signature.sig_items in
512- {uri; moduleName = cmt_modname; stamps = env.stamps; structure}
513- | _ -> File. create moduleName uri
514-
515469let addLocItem extra loc locType =
516470 if not loc.Warnings. loc_ghost then
517471 extra.locItems < - {loc; locType} :: extra.locItems
@@ -668,28 +622,76 @@ let extraForCmt ~(iterator : Tast_iterator.iterator)
668622 extraForParts parts
669623 | _ -> extraForStructureItems ~iterator []
670624
671- let fileForModule modname ~package =
672- let getFile ~moduleName ~cmt ~uri =
673- if Hashtbl. mem state.cmtCache cmt then Hashtbl. find_opt state.cmtCache cmt
674- else
675- match Shared. tryReadCmt cmt with
676- | None -> None
677- | Some infos ->
678- let file = forCmt ~module Name ~uri infos in
679- Hashtbl. replace state.cmtCache cmt file;
680- Some file
681- in
682- if Hashtbl. mem package.pathsForModule modname then (
683- let paths = Hashtbl. find package.pathsForModule modname in
625+ let fileForCmtInfos ~moduleName ~uri
626+ ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos ) =
627+ match cmt_annots with
628+ | Partial_implementation parts ->
629+ let items =
630+ parts |> Array. to_list
631+ |> Utils. filterMap (fun p ->
632+ match (p : Cmt_format.binary_part ) with
633+ | Partial_structure str -> Some str.str_items
634+ | Partial_structure_item str -> Some [str]
635+ | _ -> None )
636+ |> List. concat
637+ in
638+ let env =
639+ {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
640+ in
641+ let structure = forStructure ~env items in
642+ {File. uri; moduleName = cmt_modname; stamps = env.stamps; structure}
643+ | Partial_interface parts ->
644+ let items =
645+ parts |> Array. to_list
646+ |> Utils. filterMap (fun (p : Cmt_format.binary_part ) ->
647+ match p with
648+ | Partial_signature str -> Some str.sig_items
649+ | Partial_signature_item str -> Some [str]
650+ | _ -> None )
651+ |> List. concat
652+ in
653+ let env =
654+ {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
655+ in
656+ let structure = forSignature ~env items in
657+ {uri; moduleName = cmt_modname; stamps = env.stamps; structure}
658+ | Implementation structure ->
659+ let env =
660+ {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
661+ in
662+ let structure = forStructure ~env structure.str_items in
663+ {uri; moduleName = cmt_modname; stamps = env.stamps; structure}
664+ | Interface signature ->
665+ let env =
666+ {Env. stamps = Stamps. init () ; modulePath = File (uri, moduleName)}
667+ in
668+ let structure = forSignature ~env signature.sig_items in
669+ {uri; moduleName = cmt_modname; stamps = env.stamps; structure}
670+ | _ -> File. create moduleName uri
671+
672+ let fileForCmt ~moduleName ~cmt ~uri =
673+ match Hashtbl. find_opt state.cmtCache cmt with
674+ | Some file -> Some file
675+ | None -> (
676+ match Shared. tryReadCmt cmt with
677+ | None -> None
678+ | Some infos ->
679+ let file = fileForCmtInfos ~module Name ~uri infos in
680+ Hashtbl. replace state.cmtCache cmt file;
681+ Some file)
682+
683+ let fileForModule moduleName ~package =
684+ match Hashtbl. find_opt package.pathsForModule moduleName with
685+ | Some paths -> (
684686 let uri = getUri paths in
685687 let cmt = getCmtPath ~uri paths in
686688 Log. log (" fileForModule " ^ showPaths paths);
687- match getFile ~module Name:modname ~cmt ~uri with
689+ match fileForCmt ~cmt ~module Name ~uri with
688690 | None -> None
689691 | Some docs -> Some docs)
690- else (
691- Log. log (" No path for module " ^ modname );
692- None )
692+ | None ->
693+ Log. log (" No path for module " ^ moduleName );
694+ None
693695
694696let rec resolvePathInner ~(env : QueryEnv.t ) ~path =
695697 match path with
@@ -1037,7 +1039,7 @@ let fullForCmt ~moduleName ~package ~uri cmt =
10371039 match Shared. tryReadCmt cmt with
10381040 | None -> None
10391041 | Some infos ->
1040- let file = forCmt ~module Name ~uri infos in
1042+ let file = fileForCmtInfos ~module Name ~uri infos in
10411043 let extra = extraForFile ~file in
10421044 let env = QueryEnv. fromFile file in
10431045 let iterator = getIterator ~env ~extra ~file in
0 commit comments