@@ -569,18 +569,28 @@ let make_finalizer active (instance : Instance.t) =
569
569
Document_store. unregister_promotions active.config.document_store
570
570
to_unregister)
571
571
572
- let poll active =
572
+ let poll active last_error =
573
573
(* a single workspaces value for one iteration of the loop *)
574
574
let workspaces = active.workspaces in
575
575
let workspace_folders = Workspaces. workspace_folders workspaces in
576
576
let * res = Poll. poll active.registry in
577
577
match res with
578
578
| 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
581
591
in
582
- active.config.log ~type_: MessageType. Warning ~message
583
- | Ok _refresh -> (
592
+ `Exn exn
593
+ | Ok _refresh ->
584
594
let remaining, to_kill =
585
595
String.Map. partition active.instances ~f: (fun (running : Instance.t ) ->
586
596
let source = Instance. source running in
@@ -650,32 +660,35 @@ let poll active =
650
660
in
651
661
send (Fiber. parallel_iter ~f: Instance. stop) to_kill
652
662
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
679
692
680
693
type state =
681
694
| Closed
@@ -730,15 +743,15 @@ let create workspaces (client_capabilities : ClientCapabilities.t) diagnostics
730
743
~log
731
744
732
745
let run_loop t =
733
- Fiber. repeat_while ~init: () ~f: (fun () ->
746
+ Fiber. repeat_while ~init: `No_error ~f: (fun state ->
734
747
match ! t with
735
748
| Closed -> Fiber. return None
736
749
| Active active ->
737
- let * () = poll active in
750
+ let * state = poll active state in
738
751
(* TODO make this a bit more dynamic. if poll completes fast, wait more,
739
752
if it's slow, then wait less *)
740
753
let + () = Lev_fiber.Timer. sleepf 0.25 in
741
- Some () )
754
+ Some state )
742
755
743
756
let run t : unit Fiber.t =
744
757
Fiber. of_thunk (fun () ->
0 commit comments