Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

501 backports #1701

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion doc/dev/CACHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions emacs/merlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/ocamlmerlin/new/new_merlin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/frontend/ocamlmerlin/ocamlmerlin_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/kernel/mbrowse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -356,6 +358,15 @@ let merlin_flags = [
marg_path (fun path merlin -> {merlin with stdlib = Some path}),
"<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",
Expand Down Expand Up @@ -615,6 +626,7 @@ let initial = {

failures = [];
extension_to_reader = [(".re","reason");(".rei","reason")];
cache_period = 5;
};
query = {
filename = "*buffer*";
Expand Down
3 changes: 2 additions & 1 deletion src/kernel/mconfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ocaml/preprocess/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test-dirs/config/dot-merlin-reader/quoting.t
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"extension": ".rei",
"reader": "reason"
}
]
],
"cache_period": "5"
}

$ rm .merlin
37 changes: 37 additions & 0 deletions tests/test-dirs/server-tests/cache-time.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
$ $MERLIN server stop-server

$ cat >dune-project <<EOF
> (lang dune 2.0)
> EOF

$ cat >dune <<EOF
>
> (executable
> (name main)
> (modules main)
> EOF

$ cat > main.ml <<EOF
> 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 <main.ml

When cache time is set to large value, we keep the cache
$ $MERLIN server errors -log-file merlin_logs -cache-period 45 \
> -filename main.ml 1> /dev/null <main.ml
$ cat merlin_logs | grep -A1 "File_cache(Cmi_cache) - flush" \
> | 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 <main.ml
$ cat merlin_logs | grep -A1 "File_cache(Cmi_cache) - flush" \
> | tail -1 | sed 's/\ ".*\"//'
removing

Stop server
$ $MERLIN server stop-server
2 changes: 1 addition & 1 deletion vim/merlin/autoload/merlin.vim
Original file line number Diff line number Diff line change
@@ -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
Expand Down