@@ -198,7 +198,7 @@ run scheduler _origDir plugins captureFp = flip E.catches handlers $ do
198
198
-- recognized properly by ghc-mod
199
199
flip labelThread " scheduler" =<<
200
200
forkIO
201
- ( Scheduler. runScheduler scheduler errorHandler callbackHandler lf (passPublishDiagnostics rin ) mcradle
201
+ ( Scheduler. runScheduler scheduler errorHandler callbackHandler lf (publishDiagnostics' lf ) mcradle
202
202
`E.catch`
203
203
\ (e :: E. SomeException ) ->
204
204
errorm $ " Scheduler thread exited unexpectedly: " ++ show e
@@ -256,13 +256,9 @@ run scheduler _origDir plugins captureFp = flip E.catches handlers $ do
256
256
257
257
-- ---------------------------------------------------------------------
258
258
259
- data ReactorInput
260
- = CM FromClientMessage
261
- -- ^ injected into the reactor input by each of the individual
262
- -- callback handlers
263
- | PD J. NormalizedUri J. TextDocumentVersion DiagnosticsBySource
264
- -- ^ injected into the reactor input by any scheduler needing to
265
- -- publish additional diagnostics
259
+ type ReactorInput
260
+ = FromClientMessage
261
+ -- ^ injected into the reactor input by each of the individual callback handlers
266
262
267
263
-- ---------------------------------------------------------------------
268
264
@@ -363,10 +359,8 @@ updatePositionMap uri changes = pluginGetFile "updatePositionMap: " uri $ \file
363
359
-- ---------------------------------------------------------------------
364
360
365
361
publishDiagnostics :: (MonadIO m , MonadReader REnv m )
366
- => J. NormalizedUri -> J. TextDocumentVersion -> DiagnosticsBySource -> m ()
367
- publishDiagnostics uri' mv diags = do
368
- clientConfig <- getClientConfig
369
- let maxToSend = maxNumberOfProblems clientConfig
362
+ => Int -> J. NormalizedUri -> J. TextDocumentVersion -> DiagnosticsBySource -> m ()
363
+ publishDiagnostics maxToSend uri' mv diags = do
370
364
lf <- asks lspFuncs
371
365
publishDiagnostics' lf maxToSend uri' mv diags
372
366
@@ -421,15 +415,15 @@ reactor inp diagIn = do
421
415
liftIO $ U. logs $ " ****** reactor: got message number:" ++ show tn
422
416
423
417
case inval of
424
- CM ( RspFromClient resp@ (J. ResponseMessage _ _ _ merr) ) -> do
418
+ RspFromClient resp@ (J. ResponseMessage _ _ _ merr) -> do
425
419
liftIO $ U. logs $ " reactor:got RspFromClient:" ++ show resp
426
420
case merr of
427
421
Nothing -> return ()
428
422
Just _ -> sendErrorLog $ " Got error response:" <> decodeUtf8 (BL. toStrict $ A. encode resp)
429
423
430
424
-- -------------------------------
431
425
432
- CM ( NotInitialized _notification) -> do
426
+ NotInitialized _notification -> do
433
427
liftIO $ U. logm " ****** reactor: processing Initialized Notification"
434
428
-- Server is ready, register any specific capabilities we need
435
429
@@ -483,7 +477,7 @@ reactor inp diagIn = do
483
477
484
478
-- -------------------------------
485
479
486
- CM ( NotDidOpenTextDocument notification) -> do
480
+ NotDidOpenTextDocument notification -> do
487
481
liftIO $ U. logm " ****** reactor: processing NotDidOpenTextDocument"
488
482
let
489
483
td = notification ^. J. params . J. textDocument
@@ -495,17 +489,17 @@ reactor inp diagIn = do
495
489
496
490
-- -------------------------------
497
491
498
- CM ( NotDidChangeWatchedFiles _notification) -> do
492
+ NotDidChangeWatchedFiles _notification -> do
499
493
liftIO $ U. logm " ****** reactor: not processing NotDidChangeWatchedFiles"
500
494
501
495
-- -------------------------------
502
496
503
- CM ( NotWillSaveTextDocument _notification) -> do
497
+ NotWillSaveTextDocument _notification -> do
504
498
liftIO $ U. logm " ****** reactor: not processing NotWillSaveTextDocument"
505
499
506
500
-- -------------------------------
507
501
508
- CM ( NotDidSaveTextDocument notification) -> do
502
+ NotDidSaveTextDocument notification -> do
509
503
-- This notification is redundant, as we get the NotDidChangeTextDocument
510
504
liftIO $ U. logm " ****** reactor: processing NotDidSaveTextDocument"
511
505
let
@@ -517,7 +511,7 @@ reactor inp diagIn = do
517
511
518
512
-- -------------------------------
519
513
520
- CM ( NotDidChangeTextDocument notification) -> do
514
+ NotDidChangeTextDocument notification -> do
521
515
liftIO $ U. logm " ****** reactor: processing NotDidChangeTextDocument"
522
516
let
523
517
params = notification ^. J. params
@@ -537,7 +531,7 @@ reactor inp diagIn = do
537
531
538
532
-- -------------------------------
539
533
540
- CM ( NotDidCloseTextDocument notification) -> do
534
+ NotDidCloseTextDocument notification -> do
541
535
liftIO $ U. logm " ****** reactor: processing NotDidCloseTextDocument"
542
536
let
543
537
uri = notification ^. J. params . J. textDocument . J. uri
@@ -549,7 +543,7 @@ reactor inp diagIn = do
549
543
550
544
-- -------------------------------
551
545
552
- CM ( ReqRename req) -> do
546
+ ReqRename req -> do
553
547
liftIO $ U. logs $ " reactor:got RenameRequest:" ++ show req
554
548
-- TODO: re-enable HaRe
555
549
-- let (params, doc, pos) = reqParams req
@@ -562,7 +556,7 @@ reactor inp diagIn = do
562
556
563
557
-- -------------------------------
564
558
565
- CM ( ReqHover req) -> do
559
+ ReqHover req -> do
566
560
liftIO $ U. logs $ " reactor:got HoverRequest:" ++ show req
567
561
let params = req ^. J. params
568
562
pos = params ^. J. position
@@ -592,13 +586,13 @@ reactor inp diagIn = do
592
586
593
587
-- -------------------------------
594
588
595
- CM ( ReqCodeAction req) -> do
589
+ ReqCodeAction req -> do
596
590
liftIO $ U. logs $ " reactor:got CodeActionRequest:" ++ show req
597
591
handleCodeActionReq tn req
598
592
599
593
-- -------------------------------
600
594
601
- CM ( ReqExecuteCommand req) -> do
595
+ ReqExecuteCommand req -> do
602
596
liftIO $ U. logs $ " reactor:got ExecuteCommandRequest:" ++ show req
603
597
lf <- asks lspFuncs
604
598
@@ -671,7 +665,7 @@ reactor inp diagIn = do
671
665
672
666
-- -------------------------------
673
667
674
- CM ( ReqCompletion req) -> do
668
+ ReqCompletion req -> do
675
669
liftIO $ U. logs $ " reactor:got CompletionRequest:" ++ show req
676
670
let (_, doc, pos) = reqParams req
677
671
@@ -689,7 +683,7 @@ reactor inp diagIn = do
689
683
$ lift $ Completions. getCompletions doc prefix snippets
690
684
makeRequest hreq
691
685
692
- CM ( ReqCompletionItemResolve req) -> do
686
+ ReqCompletionItemResolve req -> do
693
687
liftIO $ U. logs $ " reactor:got CompletionItemResolveRequest:" ++ show req
694
688
snippets <- Completions. WithSnippets <$> configVal completionSnippetsOn
695
689
let origCompl = req ^. J. params
@@ -702,7 +696,7 @@ reactor inp diagIn = do
702
696
703
697
-- -------------------------------
704
698
705
- CM ( ReqDocumentHighlights req) -> do
699
+ ReqDocumentHighlights req -> do
706
700
liftIO $ U. logs $ " reactor:got DocumentHighlightsRequest:" ++ show req
707
701
let (_, doc, pos) = reqParams req
708
702
callback = reactorSend . RspDocumentHighlights . Core. makeResponseMessage req . J. List
@@ -712,7 +706,7 @@ reactor inp diagIn = do
712
706
713
707
-- -------------------------------
714
708
715
- CM ( ReqDefinition req) -> do
709
+ ReqDefinition req -> do
716
710
liftIO $ U. logs $ " reactor:got DefinitionRequest:" ++ show req
717
711
let params = req ^. J. params
718
712
doc = params ^. J. textDocument . J. uri
@@ -722,7 +716,7 @@ reactor inp diagIn = do
722
716
$ fmap J. MultiLoc <$> Hie. findDef doc pos
723
717
makeRequest hreq
724
718
725
- CM ( ReqTypeDefinition req) -> do
719
+ ReqTypeDefinition req -> do
726
720
liftIO $ U. logs $ " reactor:got DefinitionTypeRequest:" ++ show req
727
721
let params = req ^. J. params
728
722
doc = params ^. J. textDocument . J. uri
@@ -732,7 +726,7 @@ reactor inp diagIn = do
732
726
$ fmap J. MultiLoc <$> Hie. findTypeDef doc pos
733
727
makeRequest hreq
734
728
735
- CM ( ReqFindReferences req) -> do
729
+ ReqFindReferences req -> do
736
730
liftIO $ U. logs $ " reactor:got FindReferences:" ++ show req
737
731
-- TODO: implement project-wide references
738
732
let (_, doc, pos) = reqParams req
@@ -744,7 +738,7 @@ reactor inp diagIn = do
744
738
745
739
-- -------------------------------
746
740
747
- CM ( ReqDocumentFormatting req) -> do
741
+ ReqDocumentFormatting req -> do
748
742
liftIO $ U. logs $ " reactor:got FormatRequest:" ++ show req
749
743
provider <- getFormattingProvider
750
744
let params = req ^. J. params
@@ -756,7 +750,7 @@ reactor inp diagIn = do
756
750
757
751
-- -------------------------------
758
752
759
- CM ( ReqDocumentRangeFormatting req) -> do
753
+ ReqDocumentRangeFormatting req -> do
760
754
liftIO $ U. logs $ " reactor:got FormatRequest:" ++ show req
761
755
provider <- getFormattingProvider
762
756
let params = req ^. J. params
@@ -769,7 +763,7 @@ reactor inp diagIn = do
769
763
770
764
-- -------------------------------
771
765
772
- CM ( ReqDocumentSymbols req) -> do
766
+ ReqDocumentSymbols req -> do
773
767
liftIO $ U. logs $ " reactor:got Document symbol request:" ++ show req
774
768
sps <- asks symbolProviders
775
769
C. ClientCapabilities _ tdc _ _ <- asksLspFuncs Core. clientCapabilities
@@ -794,14 +788,14 @@ reactor inp diagIn = do
794
788
795
789
-- -------------------------------
796
790
797
- CM ( NotCancelRequestFromClient notif) -> do
791
+ NotCancelRequestFromClient notif -> do
798
792
liftIO $ U. logs $ " reactor:got CancelRequest:" ++ show notif
799
793
let lid = notif ^. J. params . J. id
800
794
cancelRequest lid
801
795
802
796
-- -------------------------------
803
797
804
- CM ( NotDidChangeConfiguration notif) -> do
798
+ NotDidChangeConfiguration notif -> do
805
799
liftIO $ U. logs $ " reactor:didChangeConfiguration notification:" ++ show notif
806
800
-- if hlint has been turned off, flush the diagnostics
807
801
diagsOn <- configVal hlintOn
@@ -814,15 +808,8 @@ reactor inp diagIn = do
814
808
else flushDiagnosticsBySource maxDiagnosticsToSend (Just " hlint" )
815
809
816
810
-- -------------------------------
817
-
818
- CM om -> do
811
+ om -> do
819
812
liftIO $ U. logs $ " reactor:got HandlerRequest:" ++ show om
820
-
821
- -- -------------------------------
822
-
823
- PD uri version diagnostics -> do
824
- publishDiagnostics uri version diagnostics
825
-
826
813
loop (tn + 1 )
827
814
828
815
-- Actually run the thing
@@ -956,17 +943,18 @@ requestDiagnosticsNormal tn file mVer = do
956
943
sendOneGhc :: J. DiagnosticSource -> (J. NormalizedUri , [Diagnostic ]) -> R ()
957
944
sendOneGhc pid (fileUri,ds) = do
958
945
if any (hasSeverity J. DsError ) ds
959
- then publishDiagnostics fileUri Nothing
946
+ then publishDiagnostics maxToSend fileUri Nothing
960
947
(Map. fromList [(Just " hlint" ,SL. toSortedList [] ),(Just pid,SL. toSortedList ds)])
961
948
else sendOne pid (fileUri,ds)
962
949
963
950
sendOne pid (fileUri,ds) = do
964
- publishDiagnostics fileUri Nothing (Map. fromList [(Just pid,SL. toSortedList ds)])
951
+ publishDiagnostics maxToSend fileUri Nothing (Map. fromList [(Just pid,SL. toSortedList ds)])
965
952
966
953
hasSeverity :: J. DiagnosticSeverity -> J. Diagnostic -> Bool
967
954
hasSeverity sev (J. Diagnostic _ (Just s) _ _ _ _) = s == sev
968
955
hasSeverity _ _ = False
969
- sendEmpty = publishDiagnostics (J. toNormalizedUri file) Nothing (Map. fromList [(Just " bios" ,SL. toSortedList [] )])
956
+ sendEmpty = publishDiagnostics maxToSend (J. toNormalizedUri file) Nothing (Map. fromList [(Just " bios" ,SL. toSortedList [] )])
957
+ maxToSend = maxNumberOfProblems clientConfig
970
958
971
959
let sendHlint = hlintOn clientConfig
972
960
when sendHlint $ do
@@ -1065,14 +1053,6 @@ hieHandlers rin
1065
1053
1066
1054
passHandler :: TChan ReactorInput -> (a -> FromClientMessage ) -> Core. Handler a
1067
1055
passHandler rin c notification = do
1068
- atomically $ writeTChan rin (CM (c notification))
1069
-
1070
- -- ---------------------------------------------------------------------
1071
-
1072
- -- | Generate a 'PublishDiagnostics' function that will simply insert
1073
- -- the request into the main server loop
1074
- passPublishDiagnostics :: TChan ReactorInput -> PublishDiagnostics
1075
- passPublishDiagnostics rin uri version diagnostics = do
1076
- atomically $ writeTChan rin (PD uri version diagnostics)
1056
+ atomically $ writeTChan rin (c notification)
1077
1057
1078
1058
-- ---------------------------------------------------------------------
0 commit comments