diff --git a/ocaml-lsp-server/src/document.ml b/ocaml-lsp-server/src/document.ml index e7986d524..3894c8c29 100644 --- a/ocaml-lsp-server/src/document.ml +++ b/ocaml-lsp-server/src/document.ml @@ -106,10 +106,6 @@ let tdoc = function let uri t = Text_document.documentUri (tdoc t) -let is_merlin = function - | Other _ -> false - | Merlin _ -> true - let kind = function | Merlin _ as t -> `Merlin (Kind.of_fname (Uri.to_path (uri t))) | Other _ -> `Other diff --git a/ocaml-lsp-server/src/document.mli b/ocaml-lsp-server/src/document.mli index 96d80090f..68f6dcfcf 100644 --- a/ocaml-lsp-server/src/document.mli +++ b/ocaml-lsp-server/src/document.mli @@ -22,8 +22,6 @@ module Kind : sig | Impl end -val is_merlin : t -> bool - val kind : t -> [ `Merlin of Kind.t | `Other ] val syntax : t -> Syntax.t diff --git a/ocaml-lsp-server/src/dune.ml b/ocaml-lsp-server/src/dune.ml index 406d54c00..6c90f8ec4 100644 --- a/ocaml-lsp-server/src/dune.ml +++ b/ocaml-lsp-server/src/dune.ml @@ -257,9 +257,9 @@ end = struct | Failed | Interrupted | Success -> let* () = Document_store.change_all document_store ~f:(fun doc -> - match Document.is_merlin doc with - | false -> Fiber.return doc - | true -> + match Document.kind doc with + | `Other -> Fiber.return doc + | `Merlin _ -> let doc = Document.update_text doc [] in let+ () = Diagnostics.merlin_diagnostics diagnostics doc diff --git a/ocaml-lsp-server/src/ocaml_lsp_server.ml b/ocaml-lsp-server/src/ocaml_lsp_server.ml index a2a45cd47..627db9a1a 100644 --- a/ocaml-lsp-server/src/ocaml_lsp_server.ml +++ b/ocaml-lsp-server/src/ocaml_lsp_server.ml @@ -269,7 +269,8 @@ module Formatter = struct let run rpc doc = let state : State.t = Server.state rpc in - if Document.is_merlin doc then + match Document.kind doc with + | `Merlin _ -> ( let* res = let* res = Ocamlformat_rpc.format_doc state.ocamlformat_rpc doc in match res with @@ -289,8 +290,8 @@ module Formatter = struct task_if_running state.detached ~f:(fun () -> Server.notification rpc (ShowMessage msg)) in - Jsonrpc.Response.Error.raise error - else + Jsonrpc.Response.Error.raise error) + | `Other -> ( match Dune.for_doc (State.dune state) doc with | [] -> let message = @@ -314,7 +315,7 @@ module Formatter = struct State.log_msg rpc ~type_:MessageType.Warning ~message in let+ to_ = Dune.Instance.format_dune_file dune doc in - Some (Diff.edit ~from:(Document.text doc) ~to_) + Some (Diff.edit ~from:(Document.text doc) ~to_)) end let location_of_merlin_loc uri : _ -> (_, string) result = function @@ -370,13 +371,14 @@ let signature_help (state : State.t) in (* TODO use merlin resources efficiently and do everything in 1 thread *) let* application_signature = - if Document.is_merlin doc then + match Document.kind doc with + | `Other -> Fiber.return None + | `Merlin _ -> Document.with_pipeline_exn doc (fun pipeline -> let typer = Mpipeline.typer_result pipeline in let pos = Mpipeline.get_lexing_pos pipeline pos in let node = Mtyper.node_at typer pos in Signature_help.application_signature node ~prefix) - else Fiber.return None in match application_signature with | None ->