diff --git a/CHANGES.md b/CHANGES.md index 54548eba5b..7c2f596847 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ merlin NEXT_VERSION + merlin binary - Fix a follow-up issue to the preference of non-ghost nodes introduced in #1660 (#1690, fixes #1689) + - Add `--cache-period` flag, that sets cache invalidation period. (#1698) + editor modes - vim: load merlin when Vim is compiled with +python3/dyn (e.g. MacVim) diff --git a/doc/dev/CACHING.md b/doc/dev/CACHING.md index 4f237121ee..c422cb40c0 100644 --- a/doc/dev/CACHING.md +++ b/doc/dev/CACHING.md @@ -77,7 +77,8 @@ to be used anymore. `Mocaml.flush_caches` remove all files that have changed on disk or that haven't been used for some time. By default, `ocamlmerlin_server` remove -entries that haven't been used in the last 300 seconds. +entries that haven't been used in the last 5 minutes. This behavior can be +changed with `--cache-period` flag. Since this involve stating each entry, the check is done after answering. diff --git a/emacs/merlin.el b/emacs/merlin.el index c13fac943a..bc2df647cb 100644 --- a/emacs/merlin.el +++ b/emacs/merlin.el @@ -194,6 +194,10 @@ a new window or not." "If non-nil, use this file for the log file (should be an absolute path)." :group 'merlin :type 'file) +(defcustom merlin-cache-period nil + "If non-nil, use this value for cache period (measured in minutes)." + :group 'merlin :type 'natnum) + (defcustom merlin-arrow-keys-type-enclosing t "If non-nil, after a type enclosing, C-up and C-down are used to go up and down the AST. In addition, C-w copies the type to the @@ -550,6 +554,8 @@ argument (lookup appropriate binary, setup logging, pass global settings)" (cons "-flags" merlin-buffer-flags)) (when filename (cons "-filename" filename)) + (when merlin-cache-period + (cons "-cache-period" (number-to-string merlin-cache-period))) args)) ;; Log last commands (setq merlin-debug-last-commands diff --git a/src/frontend/ocamlmerlin/new/new_merlin.ml b/src/frontend/ocamlmerlin/new/new_merlin.ml index ef16dbca8b..213835b0fb 100644 --- a/src/frontend/ocamlmerlin/new/new_merlin.ml +++ b/src/frontend/ocamlmerlin/new/new_merlin.ml @@ -91,6 +91,8 @@ let run = function (* Start processing query *) Logger.with_log_file Mconfig.(config.merlin.log_file) ~sections:Mconfig.(config.merlin.log_sections) @@ fun () -> + Mocaml.flush_caches + ~older_than:(float_of_int (60 * Mconfig.(config.merlin.cache_period))) (); File_id.with_cache @@ fun () -> let source = Msource.make (Misc.string_of_file stdin) in let pipeline = Mpipeline.make config source in diff --git a/src/frontend/ocamlmerlin/ocamlmerlin_server.ml b/src/frontend/ocamlmerlin/ocamlmerlin_server.ml index c74d8bc7ab..0cc4cbc29b 100644 --- a/src/frontend/ocamlmerlin/ocamlmerlin_server.ml +++ b/src/frontend/ocamlmerlin/ocamlmerlin_server.ml @@ -33,7 +33,6 @@ module Server = struct let server_accept merlinid server = let rec loop total = - Mocaml.flush_caches ~older_than:300.0 (); let merlinid' = File_id.get Sys.executable_name in if total > merlin_timeout || not (File_id.check merlinid merlinid') then diff --git a/src/kernel/mconfig.ml b/src/kernel/mconfig.ml index f999b7f6b0..d9d859c102 100644 --- a/src/kernel/mconfig.ml +++ b/src/kernel/mconfig.ml @@ -92,8 +92,9 @@ type merlin = { flags_applied : string list with_workdir list; failures : string list; - extension_to_reader : (string * string) list + extension_to_reader : (string * string) list; + cache_period : int } let dump_merlin x = @@ -129,7 +130,8 @@ let dump_merlin x = "extension", `String suffix; "reader", `String reader; ]) x.extension_to_reader - ) + ); + "cache_period" , Json.string (string_of_int x.cache_period) ] module Verbosity = struct @@ -358,6 +360,15 @@ let merlin_flags = [ marg_path (fun path merlin -> {merlin with stdlib = Some path}), " Change path of ocaml standard library" ); + ( + "-cache-period", + Marg.param "int" (fun prot merlin -> + try {merlin with cache_period = (int_of_string prot)} + with _ -> invalid_arg "Valid value is int"; + ), + "Change file cache retention period. It's measured in minutes. \ + Default value is 5." + ); ( (* Legacy support for janestreet. Ignored. To be removed soon. *) "-attributes-allowed", @@ -627,6 +638,7 @@ let initial = { failures = []; extension_to_reader = [(".re","reason");(".rei","reason")]; + cache_period = 5; }; query = { filename = "*buffer*"; diff --git a/src/kernel/mconfig.mli b/src/kernel/mconfig.mli index e2cff29a73..6042ba6fbf 100644 --- a/src/kernel/mconfig.mli +++ b/src/kernel/mconfig.mli @@ -49,7 +49,8 @@ type merlin = { flags_applied : string list with_workdir list; failures : string list; - extension_to_reader : (string * string) list + extension_to_reader : (string * string) list; + cache_period : int } val dump_merlin : merlin -> json diff --git a/tests/test-dirs/config/dot-merlin-reader/quoting.t b/tests/test-dirs/config/dot-merlin-reader/quoting.t index a9363083d5..c420427db7 100644 --- a/tests/test-dirs/config/dot-merlin-reader/quoting.t +++ b/tests/test-dirs/config/dot-merlin-reader/quoting.t @@ -66,7 +66,8 @@ "extension": ".rei", "reader": "reason" } - ] + ], + "cache_period": "5" } $ rm .merlin diff --git a/tests/test-dirs/server-tests/cache-time.t b/tests/test-dirs/server-tests/cache-time.t new file mode 100644 index 0000000000..0069d3e3dd --- /dev/null +++ b/tests/test-dirs/server-tests/cache-time.t @@ -0,0 +1,37 @@ + $ $MERLIN server stop-server + + $ cat >dune-project < (lang dune 2.0) + > EOF + + $ cat >dune < + > (executable + > (name main) + > (modules main) + > EOF + + $ cat > main.ml < let () = print_int 0 + > EOF + +Let's populate file cache + $ $MERLIN server errors -log-file merlin_logs -cache-period 45 \ + > -filename main.ml 1> /dev/null -filename main.ml 1> /dev/null | tail -1 | sed 's/\ ".*\"//' + keeping + +When cache time is set to 0, file cache gets flushed + $ $MERLIN server errors -log-file merlin_logs -cache-period 0 \ + > -filename main.ml 1> /dev/null | tail -1 | sed 's/\ ".*\"//' + removing + +Stop server + $ $MERLIN server stop-server