Skip to content

Commit

Permalink
index: cache files (and move to another library)
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Feb 22, 2024
1 parent 38d930e commit e71a49e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/analysis/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
-open Merlin_utils
-open Merlin_specific
-open Merlin_extend
-open Merlin_kernel)
-open Merlin_kernel
-open Merlin_index_format)
(libraries
merlin_config
merlin_specific
merlin_extend
merlin_kernel
merlin_utils
merlin_index_format
ocaml_parsing
ocaml_preprocess
query_protocol
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/occurrences.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ let locs_of ~config ~env ~typer_result ~pos ~scope path =
let exception File_changed in
try
let locs = List.filter_map config.merlin.index_files ~f:(fun file ->
let external_index = Index_format.read_exn ~file in
let external_index = Index_cache.read file in
Hashtbl.find_opt external_index.defs def_uid
|> Option.map ~f:(fun locs -> LidSet.filter (fun {loc; _} ->
(* We ignore external results that concern the current buffer *)
Expand Down
10 changes: 10 additions & 0 deletions src/index-format/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(library
(name merlin_index_format)
(public_name merlin-lib.index_format)
(flags
:standard
-open Ocaml_parsing
-open Ocaml_typing
-open Ocaml_utils
-open Merlin_utils)
(libraries ocaml_parsing ocaml_typing ocaml_utils merlin_utils))
5 changes: 5 additions & 0 deletions src/index-format/index_cache.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include File_cache.Make (struct
type t = Index_format.index
let read file = Index_format.read_exn ~file
let cache_name = "Index_cache"
end)
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let ext = "ocaml-index"
let magic_number = "Merl2023I001"

let write ~file index =
Merlin_utils.Misc.output_to_file_via_temporary ~mode:[ Open_binary ] file
Misc.output_to_file_via_temporary ~mode:[ Open_binary ] file
(fun _temp_file_name oc ->
output_string oc magic_number;
output_value oc (index : index))
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/dune
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-open Merlin_extend)
(libraries merlin_config os_ipc ocaml_parsing ocaml_preprocess ocaml_typing
ocaml_utils merlin_extend merlin_specific merlin_utils
merlin_dot_protocol unix str))
merlin_dot_protocol merlin_index_format unix str))

(rule
(targets standard_library.ml)
Expand Down
3 changes: 2 additions & 1 deletion src/kernel/mocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@ let clear_caches () = (
(* Flush cache *)
let flush_caches ?older_than () = (
Cmi_cache.flush ?older_than ();
Cmt_cache.flush ?older_than ()
Cmt_cache.flush ?older_than ();
Merlin_index_format.Index_cache.flush ?older_than ()
)

0 comments on commit e71a49e

Please sign in to comment.