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