From 69ca10081cdfe94bd07f086c219ca82c982ad1a3 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sun, 23 Oct 2022 17:55:48 +0200 Subject: [PATCH 1/3] when testing: record the source rule in diagnostics --- ghcide/src/Development/IDE/Core/Shake.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Core/Shake.hs b/ghcide/src/Development/IDE/Core/Shake.hs index 5e51fd0fba..a1e98a65e2 100644 --- a/ghcide/src/Development/IDE/Core/Shake.hs +++ b/ghcide/src/Development/IDE/Core/Shake.hs @@ -1199,7 +1199,7 @@ updateFileDiagnostics :: MonadIO m -> ShakeExtras -> [(ShowDiagnostic,Diagnostic)] -- ^ current results -> m () -updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv} current = +updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv, ideTesting} current0 = liftIO $ withTrace ("update diagnostics " <> fromString(fromNormalizedFilePath fp)) $ \ addTag -> do addTag "key" (show k) let (currentShown, currentHidden) = partition ((== ShowDiag) . fst) current @@ -1208,6 +1208,7 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti addTagUnsafe msg t x v = unsafePerformIO(addTag (msg <> t) x) `seq` v update :: (forall a. String -> String -> a -> a) -> [Diagnostic] -> STMDiagnosticStore -> STM [Diagnostic] update addTagUnsafe new store = addTagUnsafe "count" (show $ Prelude.length new) $ setStageDiagnostics addTagUnsafe uri ver (renderKey k) new store + current = second diagsFromRule <$> current0 addTag "version" (show ver) mask_ $ do -- Mask async exceptions to ensure that updated diagnostics are always @@ -1230,6 +1231,11 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti LSP.sendNotification LSP.STextDocumentPublishDiagnostics $ LSP.PublishDiagnosticsParams (fromNormalizedUri uri) (fmap fromIntegral ver) (List newDiags) return action + where + diagsFromRule c + | coerce ideTesting = c{_source = ((T.pack(show k) <> ":") <>) <$> _source c} + | otherwise = c + newtype Priority = Priority Double From db83076427033a1889da34e7b16b7d83ec7ce539 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 26 Oct 2022 19:54:02 +0200 Subject: [PATCH 2/3] Use _code field --- ghcide/src/Development/IDE/Core/Shake.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Core/Shake.hs b/ghcide/src/Development/IDE/Core/Shake.hs index a1e98a65e2..adc77d13a7 100644 --- a/ghcide/src/Development/IDE/Core/Shake.hs +++ b/ghcide/src/Development/IDE/Core/Shake.hs @@ -1232,8 +1232,9 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti LSP.PublishDiagnosticsParams (fromNormalizedUri uri) (fmap fromIntegral ver) (List newDiags) return action where + diagsFromRule :: Diagnostic -> Diagnostic diagsFromRule c - | coerce ideTesting = c{_source = ((T.pack(show k) <> ":") <>) <$> _source c} + | coerce ideTesting = c{_code = Just $ InR $ T.pack(show k)} | otherwise = c From 5acffecdc441a76ba33d924786285f6aa56ad0f2 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Tue, 1 Nov 2022 05:24:05 +0100 Subject: [PATCH 3/3] Moce to diagnostic related information --- ghcide/src/Development/IDE/Core/Shake.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/Shake.hs b/ghcide/src/Development/IDE/Core/Shake.hs index adc77d13a7..2f2234cbca 100644 --- a/ghcide/src/Development/IDE/Core/Shake.hs +++ b/ghcide/src/Development/IDE/Core/Shake.hs @@ -1233,8 +1233,18 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti return action where diagsFromRule :: Diagnostic -> Diagnostic - diagsFromRule c - | coerce ideTesting = c{_code = Just $ InR $ T.pack(show k)} + diagsFromRule c@Diagnostic{_range} + | coerce ideTesting = c + {_relatedInformation = + Just $ List [ + DiagnosticRelatedInformation + (Location + (filePathToUri $ fromNormalizedFilePath fp) + _range + ) + (T.pack $ show k) + ] + } | otherwise = c