File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ module Language.LSP.Diagnostics (
11
11
StoreItem (.. ),
12
12
partitionBySource ,
13
13
flushBySource ,
14
+ flushBySourceAndUri ,
14
15
updateDiagnostics ,
15
16
getDiagnosticParamsFor ,
16
17
@@ -41,8 +42,10 @@ all prior entries for the Uri.
41
42
42
43
type DiagnosticStore = HM. HashMap J. NormalizedUri StoreItem
43
44
44
- data StoreItem
45
- = StoreItem (Maybe J. Int32 ) DiagnosticsBySource
45
+ data StoreItem = StoreItem
46
+ { documentVersion :: Maybe J. Int32
47
+ , diagnostics :: DiagnosticsBySource
48
+ }
46
49
deriving (Show , Eq )
47
50
48
51
type DiagnosticsBySource = Map. Map (Maybe Text ) (SL. SortedList J. Diagnostic )
@@ -60,6 +63,13 @@ flushBySource store (Just source) = HM.map remove store
60
63
where
61
64
remove (StoreItem mv diags) = StoreItem mv (Map. delete (Just source) diags)
62
65
66
+ flushBySourceAndUri :: DiagnosticStore -> Maybe Text -> J. NormalizedUri -> DiagnosticStore
67
+ flushBySourceAndUri store msource uri = HM. mapWithKey remove store
68
+ where
69
+ remove k item
70
+ | k == uri = item{diagnostics = Map. delete msource $ diagnostics item}
71
+ | otherwise = item
72
+
63
73
-- ---------------------------------------------------------------------
64
74
65
75
updateDiagnostics ::
Original file line number Diff line number Diff line change @@ -655,6 +655,29 @@ flushDiagnosticsBySource maxDiagnosticCount msource = join $ stateState resDiagn
655
655
656
656
-- ---------------------------------------------------------------------
657
657
658
+ {- | Remove all diagnostics from a particular uri and source, and send the updates to
659
+ the client.
660
+ -}
661
+ flushDiagnosticsBySourceAndUri ::
662
+ MonadLsp config m =>
663
+ -- | Max number of diagnostics to send
664
+ Int ->
665
+ Maybe Text ->
666
+ NormalizedUri ->
667
+ m ()
668
+ flushDiagnosticsBySourceAndUri maxDiagnosticCount msource uri = join $ stateState resDiagnostics $ \ oldDiags ->
669
+ let ! newDiags = flushBySourceAndUri oldDiags msource uri
670
+ -- Send the updated diagnostics to the client
671
+ act = forM_ (HM. keys newDiags) $ \ uri' -> do
672
+ let mdp = getDiagnosticParamsFor maxDiagnosticCount newDiags uri'
673
+ case mdp of
674
+ Nothing -> return ()
675
+ Just params -> do
676
+ sendToClient $ L. fromServerNot $ L. TNotificationMessage " 2.0" L. SMethod_TextDocumentPublishDiagnostics params
677
+ in (act, newDiags)
678
+
679
+ -- ---------------------------------------------------------------------
680
+
658
681
{- | The changes in a workspace edit should be applied from the end of the file
659
682
toward the start. Sort them into this order.
660
683
-}
You can’t perform that action at this time.
0 commit comments