Skip to content

Commit 647cd35

Browse files
committed
fix(rpc): quiet down dune registry polling
Signed-off-by: Rudi Grinberg <[email protected]> ps-id: B641F46A-2156-4487-AC08-C4D509562ECB
1 parent 91b2fa6 commit 647cd35

File tree

1 file changed

+47
-34
lines changed

1 file changed

+47
-34
lines changed

ocaml-lsp-server/src/dune.ml

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,28 @@ let make_finalizer active (instance : Instance.t) =
569569
Document_store.unregister_promotions active.config.document_store
570570
to_unregister)
571571

572-
let poll active =
572+
let poll active last_error =
573573
(* a single workspaces value for one iteration of the loop *)
574574
let workspaces = active.workspaces in
575575
let workspace_folders = Workspaces.workspace_folders workspaces in
576576
let* res = Poll.poll active.registry in
577577
match res with
578578
| Error exn ->
579-
let message =
580-
sprintf "failed to poll dune registry. %s" (Printexc.to_string exn)
579+
let+ () =
580+
match
581+
match last_error with
582+
| `No_error -> `Print
583+
| `Exn exn' -> if Poly.equal exn exn' then `Skip else `Print
584+
with
585+
| `Skip -> Fiber.return ()
586+
| `Print ->
587+
let message =
588+
sprintf "failed to poll dune registry. %s" (Printexc.to_string exn)
589+
in
590+
active.config.log ~type_:MessageType.Warning ~message
581591
in
582-
active.config.log ~type_:MessageType.Warning ~message
583-
| Ok _refresh -> (
592+
`Exn exn
593+
| Ok _refresh ->
584594
let remaining, to_kill =
585595
String.Map.partition active.instances ~f:(fun (running : Instance.t) ->
586596
let source = Instance.source running in
@@ -650,32 +660,35 @@ let poll active =
650660
in
651661
send (Fiber.parallel_iter ~f:Instance.stop) to_kill
652662
in
653-
match connected with
654-
| [] -> Fiber.return ()
655-
| _ ->
656-
active.instances <-
657-
List.fold_left connected ~init:active.instances
658-
~f:(fun acc (instance : Instance.t) ->
659-
let source = Instance.source instance in
660-
(* this is guaranteed not to raise since we don't connect to more
661-
than one dune instance per workspace *)
662-
String.Map.add_exn acc (Registry.Dune.root source) instance);
663-
Fiber.parallel_iter connected ~f:(fun (instance : Instance.t) ->
664-
let cleanup = make_finalizer active instance in
665-
let* (_ : (unit, unit) result) =
666-
Fiber.map_reduce_errors
667-
(module Monoid.Unit)
668-
(fun () -> Instance.run instance)
669-
~on_error:(fun exn ->
670-
let message =
671-
Format.asprintf "disconnected %s:@.%a"
672-
(Registry.Dune.root (Instance.source instance))
673-
Exn_with_backtrace.pp_uncaught exn
674-
in
675-
let* () = active.config.log ~type_:Error ~message in
676-
Lazy_fiber.force cleanup)
677-
in
678-
Lazy_fiber.force cleanup))
663+
let+ () =
664+
match connected with
665+
| [] -> Fiber.return ()
666+
| _ ->
667+
active.instances <-
668+
List.fold_left connected ~init:active.instances
669+
~f:(fun acc (instance : Instance.t) ->
670+
let source = Instance.source instance in
671+
(* this is guaranteed not to raise since we don't connect to more
672+
than one dune instance per workspace *)
673+
String.Map.add_exn acc (Registry.Dune.root source) instance);
674+
Fiber.parallel_iter connected ~f:(fun (instance : Instance.t) ->
675+
let cleanup = make_finalizer active instance in
676+
let* (_ : (unit, unit) result) =
677+
Fiber.map_reduce_errors
678+
(module Monoid.Unit)
679+
(fun () -> Instance.run instance)
680+
~on_error:(fun exn ->
681+
let message =
682+
Format.asprintf "disconnected %s:@.%a"
683+
(Registry.Dune.root (Instance.source instance))
684+
Exn_with_backtrace.pp_uncaught exn
685+
in
686+
let* () = active.config.log ~type_:Error ~message in
687+
Lazy_fiber.force cleanup)
688+
in
689+
Lazy_fiber.force cleanup)
690+
in
691+
`No_error
679692

680693
type state =
681694
| Closed
@@ -730,15 +743,15 @@ let create workspaces (client_capabilities : ClientCapabilities.t) diagnostics
730743
~log
731744

732745
let run_loop t =
733-
Fiber.repeat_while ~init:() ~f:(fun () ->
746+
Fiber.repeat_while ~init:`No_error ~f:(fun state ->
734747
match !t with
735748
| Closed -> Fiber.return None
736749
| Active active ->
737-
let* () = poll active in
750+
let* state = poll active state in
738751
(* TODO make this a bit more dynamic. if poll completes fast, wait more,
739752
if it's slow, then wait less *)
740753
let+ () = Lev_fiber.Timer.sleepf 0.25 in
741-
Some ())
754+
Some state)
742755

743756
let run t : unit Fiber.t =
744757
Fiber.of_thunk (fun () ->

0 commit comments

Comments
 (0)