From e6bd3d42cb214f81f83321b2bea007d434fd48ac Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Jun 2022 13:51:52 -0500 Subject: [PATCH] fix(ocamllsp): infer intf for closed docs This commit fixes a bug when inferring the interface of a module whose implementation hasn't been opened. Since the module hasn't been opened by the user, we shouldn't open in the document store and confuse the dynamic registration subscription manager. In particular, if there is a promotion pending for the document, this would wrongly remove the dynamic registration. Signed-off-by: Rudi Grinberg ps-id: 70ff54c0-ab14-4ed5-82ed-e238173c0203 --- ocaml-lsp-server/src/inference.ml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ocaml-lsp-server/src/inference.ml b/ocaml-lsp-server/src/inference.ml index 51153a378..11f715e6e 100644 --- a/ocaml-lsp-server/src/inference.ml +++ b/ocaml-lsp-server/src/inference.ml @@ -31,7 +31,7 @@ let language_id_of_fname s = | ext -> Code_error.raise "unsupported file extension" [ ("extension", String ext) ] -let force_open_document (state : State.t) uri = +let open_document_from_file (state : State.t) uri = let filename = Uri.to_path uri in Fiber.of_thunk (fun () -> match Io.String_path.read_file filename with @@ -47,11 +47,10 @@ let force_open_document (state : State.t) uri = let params = DidOpenTextDocumentParams.create ~textDocument:text_document in - let* doc = + let+ doc = Document.make (State.wheel state) state.merlin_config ~merlin_thread:state.merlin params in - let+ () = Document_store.open_document state.store doc in Some doc) let infer_intf (state : State.t) doc = @@ -66,7 +65,7 @@ let infer_intf (state : State.t) doc = let* impl = match Document_store.get_opt state.store impl_uri with | Some impl -> Fiber.return (Some impl) - | None -> force_open_document state impl_uri + | None -> open_document_from_file state impl_uri in match impl with | None -> Fiber.return None