@@ -512,10 +512,17 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
512512 {uri; moduleName = cmt_modname; stamps = env.stamps; structure}
513513 | _ -> File. create moduleName uri
514514
515- let fileForCmt ~moduleName ~uri cmt =
516- match Shared. tryReadCmt cmt with
517- | None -> None
518- | Some infos -> Some (forCmt ~module Name ~uri infos)
515+ let fileForCmt ~moduleName ~cmt ~uri =
516+ if Hashtbl. mem state.cmtCache cmt then
517+ let file = Hashtbl. find state.cmtCache cmt in
518+ Some file
519+ else
520+ match Shared. tryReadCmt cmt with
521+ | None -> None
522+ | Some infos ->
523+ let file = forCmt ~module Name ~uri infos in
524+ Hashtbl. replace state.cmtCache cmt file;
525+ Some file
519526
520527let addLocItem extra loc locType =
521528 if not loc.Warnings. loc_ghost then
@@ -673,42 +680,14 @@ let extraForCmt ~(iterator : Tast_iterator.iterator)
673680 extraForParts parts
674681 | _ -> extraForStructureItems ~iterator []
675682
676- let newFileForCmt ~moduleName cmtCache changed ~cmt ~uri =
677- match fileForCmt ~module Name ~uri cmt with
678- | None -> None
679- | Some file ->
680- Hashtbl. replace cmtCache cmt (changed, file);
681- Some file
682-
683- let fileForCmt ~moduleName ~cmt ~uri state =
684- if Hashtbl. mem state.cmtCache cmt then
685- let mtime, docs = Hashtbl. find state.cmtCache cmt in
686- (* TODO: I should really throttle this mtime checking to like every 50 ms or so *)
687- match Files. getMtime cmt with
688- | None ->
689- Log. log
690- (" \226\154\160\239\184\143 cannot get docs for nonexistant cmt " ^ cmt);
691- None
692- | Some changed ->
693- if changed > mtime then
694- newFileForCmt ~module Name state.cmtCache changed ~cmt ~uri
695- else Some docs
696- else
697- match Files. getMtime cmt with
698- | None ->
699- Log. log
700- (" \226\154\160\239\184\143 cannot get docs for nonexistant cmt " ^ cmt);
701- None
702- | Some changed -> newFileForCmt ~module Name state.cmtCache changed ~cmt ~uri
703-
704683let fileForModule modname ~package =
705684 if Hashtbl. mem package.pathsForModule modname then (
706685 let paths = Hashtbl. find package.pathsForModule modname in
707686 (* TODO: do better *)
708687 let uri = getUri paths in
709688 let cmt = getCmtPath ~uri paths in
710689 Log. log (" fileForModule " ^ showPaths paths);
711- match fileForCmt ~module Name:modname ~cmt ~uri state with
690+ match fileForCmt ~module Name:modname ~cmt ~uri with
712691 | None -> None
713692 | Some docs -> Some docs)
714693 else (
0 commit comments