@@ -28,6 +28,7 @@ module Development.IDE.Core.Shake(
2828 use_, useNoFile_, uses_,
2929 define, defineEarlyCutoff, defineOnDisk, needOnDisk, needOnDisks, fingerprintToBS,
3030 getDiagnostics, unsafeClearDiagnostics,
31+ getHiddenDiagnostics,
3132 IsIdeGlobal, addIdeGlobal, getIdeGlobalState, getIdeGlobalAction,
3233 garbageCollect,
3334 setPriority,
@@ -93,6 +94,7 @@ data ShakeExtras = ShakeExtras
9394 ,globals :: Var (HMap.HashMap TypeRep Dynamic)
9495 ,state :: Var Values
9596 ,diagnostics :: Var DiagnosticStore
97+ ,hiddenDiagnostics :: Var DiagnosticStore
9698 ,publishedDiagnostics :: Var (Map NormalizedUri [Diagnostic])
9799 -- ^ This represents the set of diagnostics that we have published.
98100 -- Due to debouncing not every change might get published.
@@ -289,6 +291,7 @@ shakeOpen getLspId eventer logger shakeProfileDir (IdeReportProgress reportProgr
289291 globals <- newVar HMap.empty
290292 state <- newVar HMap.empty
291293 diagnostics <- newVar mempty
294+ hiddenDiagnostics <- newVar mempty
292295 publishedDiagnostics <- newVar mempty
293296 debouncer <- newDebouncer
294297 positionMapping <- newVar Map.empty
@@ -400,6 +403,11 @@ getDiagnostics IdeState{shakeExtras = ShakeExtras{diagnostics}} = do
400403 val <- readVar diagnostics
401404 return $ getAllDiagnostics val
402405
406+getHiddenDiagnostics :: IdeState -> IO [FileDiagnostic]
407+getHiddenDiagnostics IdeState{shakeExtras = ShakeExtras{hiddenDiagnostics}} = do
408+ val <- readVar hiddenDiagnostics
409+ return $ getAllDiagnostics val
410+
403411-- | FIXME: This function is temporary! Only required because the files of interest doesn't work
404412unsafeClearDiagnostics :: IdeState -> IO ()
405413unsafeClearDiagnostics IdeState{shakeExtras = ShakeExtras{diagnostics}} =
@@ -408,12 +416,13 @@ unsafeClearDiagnostics IdeState{shakeExtras = ShakeExtras{diagnostics}} =
408416-- | Clear the results for all files that do not match the given predicate.
409417garbageCollect :: (NormalizedFilePath -> Bool) -> Action ()
410418garbageCollect keep = do
411− ShakeExtras{state, diagnostics,publishedDiagnostics,positionMapping} <- getShakeExtras
419+ ShakeExtras{state, diagnostics,hiddenDiagnostics,publishedDiagnostics,positionMapping} <- getShakeExtras
412420 liftIO $
413421 do newState <- modifyVar state $ \values -> do
414422 values <- evaluate $ HMap.filterWithKey (\(file, _) _ -> keep file) values
415423 return $! dupe values
416424 modifyVar_ diagnostics $ \diags -> return $! filterDiagnostics keep diags
425+ modifyVar_ hiddenDiagnostics $ \hdiags -> return $! filterDiagnostics keep hdiags
417426 modifyVar_ publishedDiagnostics $ \diags -> return $! Map.filterWithKey (\uri _ -> keep (fromUri uri)) diags
418427 let versionsForFile =
419428 Map.fromListWith Set.union $
@@ -528,7 +537,7 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) (old
528537 Failed -> (toShakeValue ShakeResult bs, Failed)
529538 Just v -> pure $ (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
530539 liftIO $ setValues state key file res
531− updateFileDiagnostics file (Key key) extras $ map snd diags
540+ updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) diags
532541 let eq = case (bs, fmap decodeShakeValue old) of
533542 (ShakeResult a, Just (ShakeResult b)) -> a == b
534543 (ShakeStale a, Just (ShakeStale b)) -> a == b
@@ -589,7 +598,7 @@ defineOnDisk act = addBuiltinRule noLint noIdentity $
589598 case mbOld of
590599 Nothing -> do
591600 (diags, mbHash) <- runAct
592− updateFileDiagnostics file (Key key) extras $ map snd diags
601+ updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) diags
593602 pure $ RunResult ChangedRecomputeDiff (fromMaybe "" mbHash) (isJust mbHash)
594603 Just old -> do
595604 current <- validateHash <$> (actionCatch getHash $ \(_ :: SomeException) -> pure "")
@@ -600,7 +609,7 @@ defineOnDisk act = addBuiltinRule noLint noIdentity $
600609 pure $ RunResult ChangedNothing (fromMaybe "" current) (isJust current)
601610 else do
602611 (diags, mbHash) <- runAct
603− updateFileDiagnostics file (Key key) extras $ map snd diags
612+ updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) diags
604613 let change
605614 | mbHash == Just old = ChangedRecomputeSame
606615 | otherwise = ChangedRecomputeDiff
@@ -656,21 +665,30 @@ updateFileDiagnostics ::
656665 NormalizedFilePath
657666 -> Key
658667 -> ShakeExtras
659− -> [Diagnostic] -- ^ current results
668+ -> [(ShowDiagnostic,Diagnostic)] -- ^ current results
660669 -> Action ()
661−updateFileDiagnostics fp k ShakeExtras{diagnostics, publishedDiagnostics, state, debouncer, eventer} current = liftIO $ do
670+updateFileDiagnostics fp k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, state, debouncer, eventer} current = liftIO $ do
662671 modTime <- join . fmap currentValue <$> getValues state GetModificationTime fp
672+ let (currentShown, currentHidden) = partition ((== ShowDiag) . fst) current
663673 mask_ $ do
664674 -- Mask async exceptions to ensure that updated diagnostics are always
665675 -- published. Otherwise, we might never publish certain diagnostics if
666676 -- an exception strikes between modifyVar but before
667677 -- publishDiagnosticsNotification.
668678 newDiags <- modifyVar diagnostics $ \old -> do
669− let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime) (T.pack $ show k) current old
679+ let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime)
680+ (T.pack $ show k) (map snd currentShown) old
670681 let newDiags = getFileDiagnostics fp newDiagsStore
671682 _ <- evaluate newDiagsStore
672683 _ <- evaluate newDiags
673684 pure $! (newDiagsStore, newDiags)
685+ modifyVar_ hiddenDiagnostics $ \old -> do
686+ let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime)
687+ (T.pack $ show k) (map snd currentHidden) old
688+ let newDiags = getFileDiagnostics fp newDiagsStore
689+ _ <- evaluate newDiagsStore
690+ _ <- evaluate newDiags
691+ return newDiagsStore
674692 let uri = filePathToUri' fp
675693 let delay = if null newDiags then 0.1 else 0
676694 registerEvent debouncer delay uri $ do
@@ -751,7 +769,7 @@ getAllDiagnostics ::
751769 DiagnosticStore ->
752770 [FileDiagnostic]
753771getAllDiagnostics =
754− concatMap (\(k,v) -> map (fromUri k,) $ getDiagnosticsFromStore v) . Map.toList
772+ concatMap (\(k,v) -> map (fromUri k,ShowDiag,) $ getDiagnosticsFromStore v) . Map.toList
755773
756774getFileDiagnostics ::
757775 NormalizedFilePath ->