From 75fd36101ff00bed23c9180e82f52276351b8e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Fri, 22 Sep 2023 12:23:40 +0200 Subject: [PATCH 1/5] Stop promoting `cmly` file (fixes #1681) --- src/ocaml/preprocess/dune | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From af5256d4423a85c9a36d89896d84c442deb9f088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Wed, 8 Nov 2023 16:56:26 +0100 Subject: [PATCH 2/5] [B] add test for dynamic python3 installation (#1688) from nilsbecker/nilsbecker-patch-1 --- CHANGES.md | 6 ++++++ vim/merlin/autoload/merlin.vim | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a8aece5d1c..a233d0bf7c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +merlin NEXT_VERSION +=================== + + + 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/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 From 06bf814616e875247276fab4f93c497c82a82164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Wed, 8 Nov 2023 16:56:54 +0100 Subject: [PATCH 3/5] [B] Break ties between ghost nodes by looking at cursor position (#1690) from ncik-roberts/fix-1689 --- CHANGES.md | 2 ++ src/kernel/mbrowse.ml | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a233d0bf7c..5886434622 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ merlin NEXT_VERSION =================== + + merlin binary + - Fix a follow-up issue to the preference of non-ghost nodes introduced in #1660 (#1690, fixes #1689) + editor modes - vim: load merlin when Vim is compiled with +python3/dyn (e.g. MacVim) 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 From 691aaf5b954645454332e28d09eced0c4cae4f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Wed, 8 Nov 2023 16:57:37 +0100 Subject: [PATCH 4/5] [B] Configurable cache retention period (#1698) from 3Rafal/cache-flush --- CHANGES.md | 1 + doc/dev/CACHING.md | 3 +- emacs/merlin.el | 6 +++ src/frontend/ocamlmerlin/new/new_merlin.ml | 2 + .../ocamlmerlin/ocamlmerlin_server.ml | 1 - src/kernel/mconfig.ml | 16 +++++++- src/kernel/mconfig.mli | 3 +- .../config/dot-merlin-reader/quoting.t | 3 +- tests/test-dirs/server-tests/cache-time.t | 37 +++++++++++++++++++ 9 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 tests/test-dirs/server-tests/cache-time.t diff --git a/CHANGES.md b/CHANGES.md index 5886434622..bbce6d3472 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 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/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 From e7b2ee2b8b6837076d4b338543361740fcb273a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Wed, 8 Nov 2023 17:37:10 +0100 Subject: [PATCH 5/5] Disable windows CI until Opam 2.2 is out :finger-crossed: --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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