Skip to content

Commit b78e3be

Browse files
committed
Configurable Merlin cache period
1 parent 6bc2627 commit b78e3be

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

lsp/src/cli.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Arg = struct
1212
; mutable stdio : bool
1313
; mutable spec : (string * Arg.spec * string) list
1414
; mutable clientProcessId : int option
15+
; mutable cachePeriod : int option
1516
}
1617

1718
let port t ~name ~description =
@@ -30,6 +31,7 @@ module Arg = struct
3031
; stdio = false
3132
; spec = []
3233
; clientProcessId = None
34+
; cachePeriod = None
3335
}
3436
in
3537
let spec =
@@ -52,7 +54,7 @@ module Arg = struct
5254

5355
let clientProcessId t = t.clientProcessId
5456

55-
let channel { pipe; port; stdio; spec = _; clientProcessId = _ } :
57+
let channel { pipe; port; stdio; spec = _; clientProcessId = _; cachePeriod = _ } :
5658
(Channel.t, string) result =
5759
match (pipe, port, stdio) with
5860
| None, None, _ -> Ok Stdio

ocaml-lsp-server/bin/main.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ let () =
55
Printexc.record_backtrace true;
66
let version = ref false in
77
let read_dot_merlin = ref false in
8+
let cache_period = ref None in
89
let arg = Lsp.Cli.Arg.create () in
910
let spec =
1011
[ ("--version", Arg.Set version, "print version")
1112
; ( "--fallback-read-dot-merlin"
1213
, Arg.Set read_dot_merlin
1314
, "read Merlin config from .merlin files. The `dot-merlin-reader` \
1415
package must be installed" )
16+
; ( "--cache-period", Arg.Int (fun period -> cache_period := Some period)
17+
, "set the Merlin file cache period")
1518
]
1619
@ Cli.Arg.spec arg
1720
in
@@ -39,7 +42,8 @@ let () =
3942
let module Exn_with_backtrace = Stdune.Exn_with_backtrace in
4043
match
4144
Exn_with_backtrace.try_with
42-
(Ocaml_lsp_server.run channel ~read_dot_merlin:!read_dot_merlin)
45+
(Ocaml_lsp_server.run channel ~read_dot_merlin:!read_dot_merlin
46+
~cache_period:!cache_period)
4347
with
4448
| Ok () -> ()
4549
| Error exn ->

ocaml-lsp-server/src/merlin_config.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ module List = struct
4747
let filter_dup lst = filter_dup' ~equiv:(fun x -> x) lst
4848
end
4949

50+
let cache_period = ref None
51+
5052
module Config = struct
5153
type t =
5254
{ build_path : string list
@@ -60,6 +62,7 @@ module Config = struct
6062
; reader : string list
6163
; exclude_query_dir : bool
6264
; use_ppx_cache : bool
65+
; cache_period : int option
6366
}
6467

6568
let empty =
@@ -74,6 +77,7 @@ module Config = struct
7477
; reader = []
7578
; exclude_query_dir = false
7679
; use_ppx_cache = false
80+
; cache_period = None
7781
}
7882

7983
(* Parses suffixes pairs that were supplied as whitespace separated pairs
@@ -133,6 +137,7 @@ module Config = struct
133137
; reader = config.reader
134138
; exclude_query_dir = config.exclude_query_dir
135139
; use_ppx_cache = config.use_ppx_cache
140+
; cache_period = config.cache_period
136141
}
137142

138143
let merge t (merlin : Mconfig.merlin) failures config_path =
@@ -149,6 +154,7 @@ module Config = struct
149154
; flags_to_apply = t.flags @ merlin.flags_to_apply
150155
; failures = failures @ merlin.failures
151156
; config_path = Some config_path
157+
; cache_period = Option.value !cache_period ~default:merlin.cache_period
152158
}
153159
end
154160

ocaml-lsp-server/src/merlin_config.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type t
66

77
val should_read_dot_merlin : bool ref
88

9+
val cache_period : int option ref
10+
911
val config : t -> Mconfig.t Fiber.t
1012

1113
val destroy : t -> unit Fiber.t

ocaml-lsp-server/src/ocaml_lsp_server.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,12 @@ let run_in_directory =
917917
let for_windows = !Merlin_utils.Std.System.run_in_directory in
918918
fun () -> if Sys.win32 then for_windows else run_in_directory
919919

920-
let run channel ~read_dot_merlin () =
920+
let run channel ~read_dot_merlin ~cache_period () =
921921
Merlin_utils.Lib_config.set_program_name "ocamllsp";
922922
Merlin_utils.Lib_config.System.set_run_in_directory (run_in_directory ());
923923
Merlin_config.should_read_dot_merlin := read_dot_merlin;
924+
Merlin_config.cache_period := cache_period;
925+
924926
Unix.putenv "__MERLIN_MASTER_PID" (string_of_int (Unix.getpid ()));
925927
Lev_fiber.run ~sigpipe:`Ignore (fun () ->
926928
let* input, output = stream_of_channel channel in
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
val run : Lsp.Cli.Channel.t -> read_dot_merlin:bool -> unit -> unit
1+
val run : Lsp.Cli.Channel.t -> read_dot_merlin:bool -> cache_period:int option -> unit -> unit
22

33
module Diagnostics = Diagnostics
44
module Version = Version

0 commit comments

Comments
 (0)