Skip to content

Commit 9415e55

Browse files
pepeiborrajneira
andauthored
Trace diagnostics (#2333)
* trace rule diagnostics * disable checkProject in HLS test suite We already disable this in ghcide tests It introduces noise (traces are harder to read), and can potentially break tests too (e.g. eval plugin) * Undo breaking auto-format * fix missing import * Fix splice plugin tests * Fix test Co-authored-by: Javier Neira <[email protected]>
1 parent f54bf55 commit 9415e55

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

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

+22-13
Original file line numberDiff line numberDiff line change
@@ -956,14 +956,26 @@ defineEarlyCutoff
956956
:: IdeRule k v
957957
=> RuleBody k v
958958
-> Rules ()
959-
defineEarlyCutoff (Rule op) = addRule $ \(Q (key, file)) (old :: Maybe BS.ByteString) mode -> otTracedAction key file mode traceA $ do
960-
defineEarlyCutoff' True (==) key file old mode $ op key file
961-
defineEarlyCutoff (RuleNoDiagnostics op) = addRule $ \(Q (key, file)) (old :: Maybe BS.ByteString) mode -> otTracedAction key file mode traceA $ do
962-
defineEarlyCutoff' False (==) key file old mode $ second (mempty,) <$> op key file
959+
defineEarlyCutoff (Rule op) = addRule $ \(Q (key, file)) (old :: Maybe BS.ByteString) mode -> otTracedAction key file mode traceA $ \traceDiagnostics -> do
960+
extras <- getShakeExtras
961+
let diagnostics diags = do
962+
traceDiagnostics diags
963+
updateFileDiagnostics file (Key key) extras . map (\(_,y,z) -> (y,z)) $ diags
964+
defineEarlyCutoff' diagnostics (==) key file old mode $ op key file
965+
defineEarlyCutoff (RuleNoDiagnostics op) = addRule $ \(Q (key, file)) (old :: Maybe BS.ByteString) mode -> otTracedAction key file mode traceA $ \traceDiagnostics -> do
966+
ShakeExtras{logger} <- getShakeExtras
967+
let diagnostics diags = do
968+
traceDiagnostics diags
969+
mapM_ (\d -> liftIO $ logWarning logger $ showDiagnosticsColored [d]) diags
970+
defineEarlyCutoff' diagnostics (==) key file old mode $ second (mempty,) <$> op key file
963971
defineEarlyCutoff RuleWithCustomNewnessCheck{..} =
964972
addRule $ \(Q (key, file)) (old :: Maybe BS.ByteString) mode ->
965-
otTracedAction key file mode traceA $
966-
defineEarlyCutoff' False newnessCheck key file old mode $
973+
otTracedAction key file mode traceA $ \ traceDiagnostics -> do
974+
ShakeExtras{logger} <- getShakeExtras
975+
let diagnostics diags = do
976+
mapM_ (\d -> liftIO $ logWarning logger $ showDiagnosticsColored [d]) diags
977+
traceDiagnostics diags
978+
defineEarlyCutoff' diagnostics newnessCheck key file old mode $
967979
second (mempty,) <$> build key file
968980

969981
defineNoFile :: IdeRule k v => (k -> Action v) -> Rules ()
@@ -978,7 +990,7 @@ defineEarlyCutOffNoFile f = defineEarlyCutoff $ RuleNoDiagnostics $ \k file -> d
978990

979991
defineEarlyCutoff'
980992
:: IdeRule k v
981-
=> Bool -- ^ update diagnostics
993+
=> ([FileDiagnostic] -> Action ()) -- ^ update diagnostics
982994
-- | compare current and previous for freshness
983995
-> (BS.ByteString -> BS.ByteString -> Bool)
984996
-> k
@@ -988,7 +1000,7 @@ defineEarlyCutoff'
9881000
-> Action (Maybe BS.ByteString, IdeResult v)
9891001
-> Action (RunResult (A (RuleResult k)))
9901002
defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
991-
extras@ShakeExtras{state, progress, logger, dirtyKeys} <- getShakeExtras
1003+
ShakeExtras{state, progress, dirtyKeys} <- getShakeExtras
9921004
options <- getIdeOptions
9931005
(if optSkipProgress options key then id else inProgress progress file) $ do
9941006
val <- case old of
@@ -998,8 +1010,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
9981010
-- No changes in the dependencies and we have
9991011
-- an existing successful result.
10001012
Just (v@Succeeded{}, diags) -> do
1001-
when doDiagnostics $
1002-
updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) $ Vector.toList diags
1013+
doDiagnostics $ Vector.toList diags
10031014
return $ Just $ RunResult ChangedNothing old $ A v
10041015
_ -> return Nothing
10051016
_ ->
@@ -1028,9 +1039,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
10281039
(toShakeValue ShakeResult bs, Failed b)
10291040
Just v -> pure (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
10301041
liftIO $ setValues state key file res (Vector.fromList diags)
1031-
if doDiagnostics
1032-
then updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) diags
1033-
else forM_ diags $ \d -> liftIO $ logWarning logger $ showDiagnosticsColored [d]
1042+
doDiagnostics diags
10341043
let eq = case (bs, fmap decodeShakeValue old) of
10351044
(ShakeResult a, Just (ShakeResult b)) -> cmp a b
10361045
(ShakeStale a, Just (ShakeStale b)) -> cmp a b

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import Development.IDE.Core.RuleTypes (GhcSession (GhcSession),
4545
GhcSessionIO (GhcSessionIO))
4646
import Development.IDE.Graph (Action)
4747
import Development.IDE.Graph.Rule
48+
import Development.IDE.Types.Diagnostics (FileDiagnostic, showDiagnostics)
4849
import Development.IDE.Types.Location (Uri (..))
4950
import Development.IDE.Types.Logger (Logger (Logger), logDebug,
5051
logInfo)
@@ -128,7 +129,7 @@ otTracedAction
128129
-> NormalizedFilePath -- ^ Path to the file the action was run for
129130
-> RunMode
130131
-> (a -> String)
131-
-> Action (RunResult a) -- ^ The action
132+
-> (([FileDiagnostic] -> Action ()) -> Action (RunResult a)) -- ^ The action
132133
-> Action (RunResult a)
133134
otTracedAction key file mode result act
134135
| userTracingEnabled = fst <$>
@@ -148,8 +149,8 @@ otTracedAction key file mode result act
148149
setTag sp "changed" $ case res of
149150
RunResult x _ _ -> fromString $ show x
150151
endSpan sp)
151-
(const act)
152-
| otherwise = act
152+
(\sp -> act (liftIO . setTag sp "diagnostics" . encodeUtf8 . showDiagnostics ))
153+
| otherwise = act (\_ -> return ())
153154

154155
otTracedGarbageCollection label act
155156
| userTracingEnabled = fst <$>
@@ -296,3 +297,4 @@ repeatUntilJust nattempts action = do
296297
case res of
297298
Nothing -> repeatUntilJust (nattempts-1) action
298299
Just{} -> return res
300+

hls-test-utils/src/Test/Hls.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ runSessionWithServer' plugin conf sconf caps root s = withLock lock $ keepCurren
177177
argsDefaultHlsConfig = conf,
178178
argsLogger = logger,
179179
argsIdeOptions = \config sessionLoader ->
180-
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
180+
let ideOptions = (argsIdeOptions def config sessionLoader)
181+
{optTesting = IdeTesting True
182+
,optCheckProject = pure False
183+
}
181184
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
182185
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ idePluginsToPluginDesc (argsHlsPlugins testing)
183186
}

plugins/hls-splice-plugin/test/Main.hs

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ tests = testGroup "splice"
6464
goldenTest :: FilePath -> ExpandStyle -> Int -> Int -> TestTree
6565
goldenTest fp tc line col =
6666
goldenWithHaskellDoc splicePlugin (fp <> " (golden)") testDataDir fp "expected" "hs" $ \doc -> do
67-
_ <- waitForDiagnostics
6867
-- wait for the entire build to finish, so that code actions that
6968
-- use stale data will get uptodate stuff
7069
void waitForBuildQueue

plugins/hls-tactics-plugin/test/Utils.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mkNoCodeLensTest input =
162162
resetGlobalHoleRef
163163
runSessionForTactics $ do
164164
doc <- openDoc (input <.> "hs") "haskell"
165-
_ <- waitForDiagnostics
165+
_ <- waitForBuildQueue
166166
lenses <- fmap (reverse . filter isWingmanLens) $ getCodeLenses doc
167167
liftIO $ lenses `shouldBe` []
168168

0 commit comments

Comments
 (0)