diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f35bee0c0..297d72ad45 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,9 +38,9 @@ jobs: os: - macos-latest - ubuntu-latest - - windows-latest + # - windows-latest ocaml-compiler: - - '5.1' + - "5.1" # The type of runner that the job will run on runs-on: ${{ matrix.os }} @@ -51,12 +51,12 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 + - name: Checkout tree + uses: actions/checkout@v4 - - name: Set up OCaml ${{ matrix.ocaml-compiler }} + - name: Set-up OCaml ${{ matrix.ocaml-compiler }} uses: ocaml/setup-ocaml@v2 with: - # Version of the OCaml compiler to initialise ocaml-compiler: ${{ matrix.ocaml-compiler }} - name: Install dependencies diff --git a/CHANGES.md b/CHANGES.md index a8aece5d1c..bbce6d3472 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,12 @@ +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) + merlin 4.12 =========== Tue Sep 26 17:45:42 CEST 2023 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/mbrowse.ml b/src/kernel/mbrowse.ml index 7c8b68bfde..9ee7c27f87 100644 --- a/src/kernel/mbrowse.ml +++ b/src/kernel/mbrowse.ml @@ -120,11 +120,13 @@ let compare_locations pos l1 l2 = Location_aux.compare_pos pos l2 with | 0, 0 -> - (* Cursor inside both locations: favor closer to the end *) - if l1.Location.loc_ghost then 1 - else if l2.Location.loc_ghost then -1 - else - Lexing.compare_pos l1.Location.loc_end l2.Location.loc_end + (* Cursor inside both locations: favor non-ghost closer to the end *) + begin match l1.Location.loc_ghost, l2.Location.loc_ghost with + | true, false -> 1 + | false, true -> -1 + | _ -> + Lexing.compare_pos l1.Location.loc_end l2.Location.loc_end + end (* Cursor inside one location: it has priority *) | 0, _ -> t1_first | _, 0 -> t2_first diff --git a/src/kernel/mconfig.ml b/src/kernel/mconfig.ml index 8f46224317..6dc045063d 100644 --- a/src/kernel/mconfig.ml +++ b/src/kernel/mconfig.ml @@ -90,8 +90,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 = @@ -127,7 +128,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 @@ -356,6 +358,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", @@ -615,6 +626,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 2906337f09..998dc3110f 100644 --- a/src/kernel/mconfig.mli +++ b/src/kernel/mconfig.mli @@ -48,7 +48,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/src/ocaml/preprocess/dune b/src/ocaml/preprocess/dune index c172777d31..ee9c283fab 100644 --- a/src/ocaml/preprocess/dune +++ b/src/ocaml/preprocess/dune @@ -9,7 +9,7 @@ (menhir (modules parser_raw) (enabled_if (<> %{profile} "release")) - (mode promote) + (mode (promote (only parser_raw.ml parser_raw.mli))) (flags :standard --inspection --table --cmly)) (rule 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 diff --git a/vim/merlin/autoload/merlin.vim b/vim/merlin/autoload/merlin.vim index c743c60310..f78424cdd1 100644 --- a/vim/merlin/autoload/merlin.vim +++ b/vim/merlin/autoload/merlin.vim @@ -1,7 +1,7 @@ if !exists('g:merlin') | let g:merlin = {} | endif | let s:c = g:merlin if !exists('g:merlin_python_version') - if has('python3') + if has('python3') || has('python3_dynamic') let g:merlin_python_version = 3 elseif has('python') || has('python2') let g:merlin_python_version = 2