File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ module Language.LSP.Diagnostics (
1111 StoreItem (.. ),
1212 partitionBySource ,
1313 flushBySource ,
14+ flushBySourceAndUri ,
1415 updateDiagnostics ,
1516 getDiagnosticParamsFor ,
1617
@@ -41,8 +42,10 @@ all prior entries for the Uri.
4142
4243type DiagnosticStore = HM. HashMap J. NormalizedUri StoreItem
4344
44- data StoreItem
45- = StoreItem (Maybe J. Int32 ) DiagnosticsBySource
45+ data StoreItem = StoreItem
46+ { documentVersion :: Maybe J. Int32
47+ , diagnostics :: DiagnosticsBySource
48+ }
4649 deriving (Show , Eq )
4750
4851type DiagnosticsBySource = Map. Map (Maybe Text ) (SL. SortedList J. Diagnostic )
@@ -60,6 +63,13 @@ flushBySource store (Just source) = HM.map remove store
6063 where
6164 remove (StoreItem mv diags) = StoreItem mv (Map. delete (Just source) diags)
6265
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+
6373-- ---------------------------------------------------------------------
6474
6575updateDiagnostics ::
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ module Language.LSP.Server (
5050 -- * Diagnostics
5151 publishDiagnostics ,
5252 flushDiagnosticsBySource ,
53+ flushDiagnosticsBySourceAndUri ,
5354
5455 -- * Progress
5556 withProgress ,
Original file line number Diff line number Diff line change @@ -656,6 +656,29 @@ flushDiagnosticsBySource maxDiagnosticCount msource = join $ stateState resDiagn
656656
657657-- ---------------------------------------------------------------------
658658
659+ {- | Remove all diagnostics from a particular uri and source, and send the updates to
660+ the client.
661+ -}
662+ flushDiagnosticsBySourceAndUri ::
663+ MonadLsp config m =>
664+ -- | Max number of diagnostics to send
665+ Int ->
666+ Maybe Text ->
667+ NormalizedUri ->
668+ m ()
669+ flushDiagnosticsBySourceAndUri maxDiagnosticCount msource uri = join $ stateState resDiagnostics $ \ oldDiags ->
670+ let ! newDiags = flushBySourceAndUri oldDiags msource uri
671+ -- Send the updated diagnostics to the client
672+ act = forM_ (HM. keys newDiags) $ \ uri' -> do
673+ let mdp = getDiagnosticParamsFor maxDiagnosticCount newDiags uri'
674+ case mdp of
675+ Nothing -> return ()
676+ Just params -> do
677+ sendToClient $ L. fromServerNot $ L. TNotificationMessage " 2.0" L. SMethod_TextDocumentPublishDiagnostics params
678+ in (act, newDiags)
679+
680+ -- ---------------------------------------------------------------------
681+
659682{- | The changes in a workspace edit should be applied from the end of the file
660683 toward the start. Sort them into this order.
661684-}
You can’t perform that action at this time.
0 commit comments