Skip to content

Commit 2b94f85

Browse files
authored
Record diagnostics source rule when testing (#3301)
* when testing: record the source rule in diagnostics * Use _code field * Moce to diagnostic related information
1 parent caa5ce5 commit 2b94f85

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: ghcide/src/Development/IDE/Core/Shake.hs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ updateFileDiagnostics :: MonadIO m
11991199
-> ShakeExtras
12001200
-> [(ShowDiagnostic,Diagnostic)] -- ^ current results
12011201
-> m ()
1202-
updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv} current =
1202+
updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv, ideTesting} current0 =
12031203
liftIO $ withTrace ("update diagnostics " <> fromString(fromNormalizedFilePath fp)) $ \ addTag -> do
12041204
addTag "key" (show k)
12051205
let (currentShown, currentHidden) = partition ((== ShowDiag) . fst) current
@@ -1208,6 +1208,7 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
12081208
addTagUnsafe msg t x v = unsafePerformIO(addTag (msg <> t) x) `seq` v
12091209
update :: (forall a. String -> String -> a -> a) -> [Diagnostic] -> STMDiagnosticStore -> STM [Diagnostic]
12101210
update addTagUnsafe new store = addTagUnsafe "count" (show $ Prelude.length new) $ setStageDiagnostics addTagUnsafe uri ver (renderKey k) new store
1211+
current = second diagsFromRule <$> current0
12111212
addTag "version" (show ver)
12121213
mask_ $ do
12131214
-- Mask async exceptions to ensure that updated diagnostics are always
@@ -1230,6 +1231,22 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
12301231
LSP.sendNotification LSP.STextDocumentPublishDiagnostics $
12311232
LSP.PublishDiagnosticsParams (fromNormalizedUri uri) (fmap fromIntegral ver) (List newDiags)
12321233
return action
1234+
where
1235+
diagsFromRule :: Diagnostic -> Diagnostic
1236+
diagsFromRule c@Diagnostic{_range}
1237+
| coerce ideTesting = c
1238+
{_relatedInformation =
1239+
Just $ List [
1240+
DiagnosticRelatedInformation
1241+
(Location
1242+
(filePathToUri $ fromNormalizedFilePath fp)
1243+
_range
1244+
)
1245+
(T.pack $ show k)
1246+
]
1247+
}
1248+
| otherwise = c
1249+
12331250

12341251
newtype Priority = Priority Double
12351252

0 commit comments

Comments
 (0)