From 4500beded9a8dc5e6dde4ad1a13a7bfc9f3f9c5d Mon Sep 17 00:00:00 2001 From: xvw Date: Sun, 5 May 2024 18:00:29 +0200 Subject: [PATCH] Use `merlin-protocol.argv` in `ocamlmerlin_server` --- src/frontend/ocamlmerlin/dune | 1 + .../ocamlmerlin/ocamlmerlin_server.ml | 25 +++++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/frontend/ocamlmerlin/dune b/src/frontend/ocamlmerlin/dune index 9f6d68102..ef72026f8 100644 --- a/src/frontend/ocamlmerlin/dune +++ b/src/frontend/ocamlmerlin/dune @@ -16,6 +16,7 @@ merlin-lib.query_protocol merlin-lib.query_commands merlin-lib.ocaml_typing merlin-lib.ocaml_utils merlin-protocol.new_protocol merlin-protocol.old_protocol + merlin-protocol.argv unix str)) (executable diff --git a/src/frontend/ocamlmerlin/ocamlmerlin_server.ml b/src/frontend/ocamlmerlin/ocamlmerlin_server.ml index 962a31f7f..3af1be9c9 100644 --- a/src/frontend/ocamlmerlin/ocamlmerlin_server.ml +++ b/src/frontend/ocamlmerlin/ocamlmerlin_server.ml @@ -1,5 +1,4 @@ open New_protocol -open Old_protocol let merlin_timeout = try float_of_string (Sys.getenv "MERLIN_TIMEOUT") @@ -76,24 +75,12 @@ end let main () = (* Setup env for extensions *) Unix.putenv "__MERLIN_MASTER_PID" (string_of_int (Unix.getpid ())); - match List.tl (Array.to_list Sys.argv) with - | "single" :: args -> exit (New_merlin.run ~new_env:None None args) - | "old-protocol" :: args -> Old_merlin.run args - | ["server"; socket_path; socket_fd] -> Server.start socket_path socket_fd - | ("-help" | "--help" | "-h" | "server") :: _ -> - Printf.eprintf - "Usage: %s \n\ - Select the merlin frontend to execute. Valid values are:\n\ - \n- 'old-protocol' executes the merlin frontend from previous version.\n\ - \ It is a top level reading and writing commands in a JSON form.\n\ - \n- 'single' is a simpler frontend that reads input from stdin,\n\ - \ processes a single query and outputs result on stdout.\n\ - \n- 'server' works like 'single', but uses a background process to\n\ - \ speedup processing.\n\ - If no frontend is specified, it defaults to 'old-protocol' for\n\ - compatibility with existing editors.\n" - Sys.argv.(0) - | args -> Old_merlin.run args + let argv = Sys.argv |> Array.to_list |> List.tl in + match Argv.dispatch argv with + | Argv.Void -> () + | Argv.With_code i -> exit i + | Argv.Ask_for_server { socket_path; socket_fd } -> + Server.start socket_path socket_fd let () = Lib_config.Json.set_pretty_to_string Yojson.Basic.pretty_to_string;