@@ -54,6 +54,7 @@ import Data.Maybe
5454import Data.Either.Extra
5555import Data.List.Extra
5656import qualified Data.Text as T
57+import Development.IDE.Core.Debouncer
5758import Development.IDE.Types.Logger hiding (Priority)
5859import Language.Haskell.LSP.Diagnostics
5960import qualified Data.SortedList as SL
@@ -79,6 +80,7 @@ import Language.Haskell.LSP.Types
7980-- information we stash inside the shakeExtra field
8081data ShakeExtras = ShakeExtras
8182 {eventer :: LSP.FromServerMessage -> IO ()
83+ ,debouncer :: Debouncer Uri
8284 ,logger :: Logger
8385 ,globals :: Var (HMap.HashMap TypeRep Dynamic)
8486 ,state :: Var Values
@@ -222,6 +224,7 @@ shakeOpen eventer logger opts rules = do
222224 globals <- newVar HMap.empty
223225 state <- newVar HMap.empty
224226 diagnostics <- newVar mempty
227+ debouncer <- newDebouncer
225228 pure ShakeExtras{..}
226229 (shakeDb, shakeClose) <- shakeOpenDatabase opts{shakeExtra = addShakeExtra shakeExtras $ shakeExtra opts} rules
227230 shakeAbort <- newVar $ return ()
@@ -379,7 +382,7 @@ updateFileDiagnostics ::
379382 -> ShakeExtras
380383 -> [Diagnostic] -- ^ current results
381384 -> Action ()
382−updateFileDiagnostics fp k ShakeExtras{diagnostics, state, eventer} current = liftIO $ do
385+updateFileDiagnostics fp k ShakeExtras{diagnostics, state, debouncer, eventer} current = liftIO $ do
383386 modTime <- join <$> getValues state GetModificationTime fp
384387 mask_ $ do
385388 -- Mask async exceptions to ensure that updated diagnostics are always
@@ -391,14 +394,16 @@ updateFileDiagnostics fp k ShakeExtras{diagnostics, state, eventer} current = li
391394 let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime) (T.pack $ show k) current old
392395 let newDiags = getFileDiagnostics fp newDiagsStore
393396 pure (newDiagsStore, (newDiags, oldDiags))
394− when (newDiags /= oldDiags) $
395− eventer $ publishDiagnosticsNotification fp newDiags
397+ let uri = fromNormalizedUri $ filePathToUri' fp
398+ when (newDiags /= oldDiags) $ do
399+ let delay = if null newDiags then 0.1 else 0
400+ registerEvent debouncer delay uri $ eventer $ publishDiagnosticsNotification uri newDiags
396401
397−publishDiagnosticsNotification :: NormalizedFilePath -> [Diagnostic] -> LSP.FromServerMessage
398−publishDiagnosticsNotification fp diags =
402+publishDiagnosticsNotification :: Uri -> [Diagnostic] -> LSP.FromServerMessage
403+publishDiagnosticsNotification uri diags =
399404 LSP.NotPublishDiagnostics $
400405 LSP.NotificationMessage "2.0" LSP.TextDocumentPublishDiagnostics $
401− LSP.PublishDiagnosticsParams (fromNormalizedUri $ filePathToUri' fp) (List diags)
406+ LSP.PublishDiagnosticsParams uri (List diags)
402407
403408newtype Priority = Priority Double
404409