Skip to content

Commit 58dad3d

Browse files
committed
Trace aborted rule evaluations
1 parent 0ead217 commit 58dad3d

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

ghcide/ghcide.cabal

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ library
4848
dependent-map,
4949
dependent-sum,
5050
dlist,
51+
exceptions,
5152
extra >= 1.7.4,
5253
fuzzy,
5354
filepath,
@@ -245,6 +246,7 @@ benchmark benchHist
245246
directory,
246247
extra,
247248
filepath,
249+
lens,
248250
optparse-applicative,
249251
shake,
250252
text,

ghcide/src/Development/IDE/Core/Tracing.hs

+17-11
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import Control.Concurrent.Async (Async, async)
1515
import Control.Concurrent.Extra (Var, modifyVar_, newVar,
1616
readVar, threadDelay)
1717
import Control.Exception (evaluate)
18-
import Control.Exception.Safe (SomeException, catch)
18+
import Control.Exception.Safe (SomeException, catch,
19+
generalBracket)
1920
import Control.Monad (forM_, forever, unless, void,
2021
when, (>=>))
22+
import Control.Monad.Catch (ExitCase (..))
2123
import Control.Monad.Extra (whenJust)
2224
import Control.Monad.IO.Unlift
2325
import Control.Seq (r0, seqList, seqTuple2, using)
2426
import Data.ByteString (ByteString)
27+
import Data.ByteString.Char8 (pack)
2528
import Data.Dynamic (Dynamic)
2629
import qualified Data.HashMap.Strict as HMap
2730
import Data.IORef (modifyIORef', newIORef,
@@ -32,7 +35,7 @@ import Debug.Trace.Flags (userTracingEnabled)
3235
import Development.IDE.Core.RuleTypes (GhcSession (GhcSession),
3336
GhcSessionDeps (GhcSessionDeps),
3437
GhcSessionIO (GhcSessionIO))
35-
import Development.IDE.Graph (Action, actionBracket)
38+
import Development.IDE.Graph (Action)
3639
import Development.IDE.Graph.Rule
3740
import Development.IDE.Types.Location (Uri (..))
3841
import Development.IDE.Types.Logger (Logger, logDebug, logInfo)
@@ -83,21 +86,24 @@ otTracedAction
8386
-> Action (RunResult a) -- ^ The action
8487
-> Action (RunResult a)
8588
otTracedAction key file mode success act
86-
| userTracingEnabled =
87-
actionBracket
89+
| userTracingEnabled = fst <$>
90+
generalBracket
8891
(do
8992
sp <- beginSpan (fromString (show key))
9093
setTag sp "File" (fromString $ fromNormalizedFilePath file)
9194
setTag sp "Mode" (fromString $ show mode)
9295
return sp
9396
)
94-
endSpan
95-
(\sp -> do
96-
res <- act
97-
unless (success $ runValue res) $ setTag sp "error" "1"
98-
setTag sp "changed" $ case res of
99-
RunResult x _ _ -> fromString $ show x
100-
return res)
97+
(\sp ec -> do
98+
case ec of
99+
ExitCaseAbort -> setTag sp "aborted" "1"
100+
ExitCaseException e -> setTag sp "exception" (pack $ show e)
101+
ExitCaseSuccess res -> do
102+
unless (success $ runValue res) $ setTag sp "error" "1"
103+
setTag sp "changed" $ case res of
104+
RunResult x _ _ -> fromString $ show x
105+
endSpan sp)
106+
(\_ -> act)
101107
| otherwise = act
102108

103109
#if MIN_VERSION_ghc(8,8,0)

hls-graph/hls-graph.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ library
6161
, containers
6262
, deepseq
6363
, directory
64+
, exceptions
6465
, extra
6566
, filepath
6667
, hashable

hls-graph/src/Development/IDE/Graph/Internal/Types.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11

22

3+
{-# LANGUAGE DeriveFunctor #-}
34
{-# LANGUAGE ExistentialQuantification #-}
45
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
56
{-# LANGUAGE ScopedTypeVariables #-}
6-
{-# LANGUAGE DeriveFunctor #-}
77

88
module Development.IDE.Graph.Internal.Types where
99

1010
import Control.Applicative
1111
import Control.Concurrent.Extra
12+
import Control.Monad.Catch
1213
import Control.Monad.Fail
1314
import Control.Monad.IO.Class
1415
import Control.Monad.Trans.Reader
@@ -49,7 +50,7 @@ data SRules = SRules {
4950
-- ACTIONS
5051

5152
newtype Action a = Action {fromAction :: ReaderT SAction IO a}
52-
deriving (Monad, Applicative, Functor, MonadIO, MonadFail)
53+
deriving (Monad, Applicative, Functor, MonadIO, MonadFail, MonadThrow, MonadCatch, MonadMask)
5354

5455
data SAction = SAction {
5556
actionDatabase :: !Database,
@@ -95,8 +96,8 @@ data Status
9596
| Running (IO ()) Result (Maybe Result)
9697

9798
getResult :: Status -> Maybe Result
98-
getResult (Clean re) = Just re
99-
getResult (Dirty m_re) = m_re
99+
getResult (Clean re) = Just re
100+
getResult (Dirty m_re) = m_re
100101
getResult (Running _ _ m_re) = m_re
101102

102103
data Result = Result {

0 commit comments

Comments
 (0)