Skip to content

Commit 5e1d0df

Browse files
authored
fix: diagnostics on non dune files (#887)
Signed-off-by: Rudi Grinberg <[email protected]> ps-id: e9c8ae3f-33d9-4cfe-88f3-36008b722c2c
1 parent 4f336ae commit 5e1d0df

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

ocaml-lsp-server/src/document.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ let syntax = function
115115
| Other t -> t.syntax
116116

117117
let timer = function
118-
| Other _ -> Code_error.raise "Document.dune" []
119118
| Merlin m -> m.timer
119+
| Other _ as t ->
120+
Code_error.raise
121+
"Document.timer"
122+
[ ("t", Dyn.string @@ DocumentUri.to_string @@ uri t) ]
120123

121124
let text t = Text_document.text (tdoc t)
122125

@@ -154,7 +157,10 @@ let await task =
154157

155158
let with_pipeline (t : t) f =
156159
match t with
157-
| Other _ -> Code_error.raise "Document.dune" []
160+
| Other _ ->
161+
Code_error.raise
162+
"Document.with_pipeline"
163+
[ ("t", Dyn.string @@ DocumentUri.to_string @@ uri t) ]
158164
| Merlin t -> (
159165
let* pipeline = Lazy_fiber.force t.pipeline in
160166
let* task =

ocaml-lsp-server/src/ocaml_lsp_server.ml

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -150,38 +150,43 @@ let ocamlmerlin_reason = "ocamlmerlin-reason"
150150

151151
let set_diagnostics detached diagnostics doc =
152152
let uri = Document.uri doc in
153-
let async send =
154-
let+ () =
155-
task_if_running detached ~f:(fun () ->
156-
let timer = Document.timer doc in
157-
let* () = Lev_fiber.Timer.Wheel.cancel timer in
158-
let* () = Lev_fiber.Timer.Wheel.reset timer in
159-
let* res = Lev_fiber.Timer.Wheel.await timer in
160-
match res with
161-
| `Cancelled -> Fiber.return ()
162-
| `Ok -> send ())
163-
in
164-
()
165-
in
166-
match Document.syntax doc with
167-
| Dune | Cram | Menhir | Ocamllex -> Fiber.return ()
168-
| Reason when Option.is_none (Bin.which ocamlmerlin_reason) ->
169-
let no_reason_merlin =
170-
let message =
171-
sprintf "Could not detect %s. Please install reason" ocamlmerlin_reason
153+
match Document.kind doc with
154+
| `Other -> Fiber.return ()
155+
| `Merlin _ -> (
156+
let async send =
157+
let+ () =
158+
task_if_running detached ~f:(fun () ->
159+
let timer = Document.timer doc in
160+
let* () = Lev_fiber.Timer.Wheel.cancel timer in
161+
let* () = Lev_fiber.Timer.Wheel.reset timer in
162+
let* res = Lev_fiber.Timer.Wheel.await timer in
163+
match res with
164+
| `Cancelled -> Fiber.return ()
165+
| `Ok -> send ())
172166
in
173-
Diagnostic.create
174-
~source:Diagnostics.ocamllsp_source
175-
~range:Range.first_line
176-
~message
177-
()
167+
()
178168
in
179-
Diagnostics.set diagnostics (`Merlin (uri, [ no_reason_merlin ]));
180-
async (fun () -> Diagnostics.send diagnostics (`One uri))
181-
| Reason | Ocaml ->
182-
async (fun () ->
183-
let* () = Diagnostics.merlin_diagnostics diagnostics doc in
184-
Diagnostics.send diagnostics (`One uri))
169+
match Document.syntax doc with
170+
| Dune | Cram | Menhir | Ocamllex -> Fiber.return ()
171+
| Reason when Option.is_none (Bin.which ocamlmerlin_reason) ->
172+
let no_reason_merlin =
173+
let message =
174+
sprintf
175+
"Could not detect %s. Please install reason"
176+
ocamlmerlin_reason
177+
in
178+
Diagnostic.create
179+
~source:Diagnostics.ocamllsp_source
180+
~range:Range.first_line
181+
~message
182+
()
183+
in
184+
Diagnostics.set diagnostics (`Merlin (uri, [ no_reason_merlin ]));
185+
async (fun () -> Diagnostics.send diagnostics (`One uri))
186+
| Reason | Ocaml ->
187+
async (fun () ->
188+
let* () = Diagnostics.merlin_diagnostics diagnostics doc in
189+
Diagnostics.send diagnostics (`One uri)))
185190

186191
let on_initialize server (ip : InitializeParams.t) =
187192
let state : State.t = Server.state server in

0 commit comments

Comments
 (0)