on master help sign in
Strip path information from diagnostic messages (#158) (#546)

* Strip path information from diagnostic messages (#158) * remove a distinction between 8.6 and 8.4 from an error message test

commitc7c39827d30db801201ebacf4093cd773e753637 authorTorsten Schmits <tek@users.noreply.github.com> dateMon 11 May 2020, 16:57 (6 years ago) parent07cf929
3 files changed+24−7
src/Development/IDE/GHC/Error.hs+2−1 test/exe/Main.hs+21−5 test/src/Development/IDE/Test.hs+1−1
src/Development/IDE/GHC/Error.hs+2−1
@@ -56,7 +56,8 @@ diagFromText diagSource sev loc msg = (toNormalizedFilePath' $ srcSpanToFilename
5656-- | Produce a GHC-style error from a source span and a message.
5757diagFromErrMsg :: T.Text -> DynFlags -> ErrMsg -> [FileDiagnostic]
5858diagFromErrMsg diagSource dflags e =
59− [ diagFromText diagSource sev (errMsgSpan e) $ T.pack $ Out.showSDoc dflags $ ErrUtils.pprLocErrMsg e
59+ [ diagFromText diagSource sev (errMsgSpan e) $ T.pack $ Out.showSDoc dflags $
60+ ErrUtils.formatErrDoc dflags $ ErrUtils.errMsgDoc e
6061 | Just sev <- [toDSeverity $ errMsgSeverity e]]
6162
6263
test/exe/Main.hs+21−5
@@ -11,6 +11,7 @@ module Main (main) where
1111
1212import Control.Applicative.Combinators
1313import Control.Exception (catch)
14+import qualified Control.Lens as Lens
1415import Control.Monad
1516import Control.Monad.IO.Class (liftIO)
1617import Data.Aeson (FromJSON, Value)
@@ -32,6 +33,7 @@ import Language.Haskell.LSP.Test hiding (openDoc')
3233import Language.Haskell.LSP.Messages
3334import Language.Haskell.LSP.Types
3435import Language.Haskell.LSP.Types.Capabilities
36+import qualified Language.Haskell.LSP.Types.Lens as Lsp (diagnostics, params, message)
3537import Language.Haskell.LSP.VFS (applyChange)
3638import Network.URI
3739import System.Environment.Blank (setEnv)
@@ -231,7 +233,6 @@ diagnosticTests = testGroup "diagnostics"
231233 [ deferralTest "type error" "True" "Couldn't match expected type"
232234 , deferralTest "typed hole" "_" "Found hole"
233235 , deferralTest "out of scope var" "unbound" "Variable not in scope"
234− , deferralTest "message shows error" "True" "A.hs:3:5: error:"
235236 ]
236237
237238 , testSessionWait "remove required module" $ do
@@ -433,6 +434,25 @@ diagnosticTests = testGroup "diagnostics"
433434 ]
434435 )
435436 ]
437+ , testSessionWait "strip file path" $ do
438+ let
439+ name = "Testing"
440+ content = T.unlines
441+ [ "module " <> name <> " where"
442+ , "value :: Maybe ()"
443+ , "value = [()]"
444+ ]
445+ _ <- openDoc' (T.unpack name <> ".hs") "haskell" content
446+ notification <- skipManyTill anyMessage diagnostic
447+ let
448+ offenders =
449+ Lsp.params .
450+ Lsp.diagnostics .
451+ Lens.folded .
452+ Lsp.message .
453+ Lens.filtered (T.isInfixOf ("/" <> name <> ".hs:"))
454+ failure msg = liftIO $ assertFailure $ "Expected file path to be stripped but got " <> T.unpack msg
455+ Lens.mapMOf_ offenders failure notification
436456 ]
437457
438458codeActionTests :: TestTree
@@ -729,11 +749,7 @@ removeImportTests = testGroup "remove import actions"
729749 _ <- waitForDiagnostics
730750 [CACodeAction action@CodeAction { _title = actionTitle }]
731751 <- getCodeActions docB (Range (Position 2 0) (Position 2 5))
732−#if MIN_GHC_API_VERSION(8,6,0)
733752 liftIO $ "Remove !!, <?> from import" @=? actionTitle
734−#else
735− liftIO $ "Remove A.!!, A.<?> from import" @=? actionTitle
736−#endif
737753 executeCodeAction action
738754 contentAfterAction <- documentContents docB
739755 let expectedContentAfterAction = T.unlines
test/src/Development/IDE/Test.hs+1−1
@@ -103,7 +103,7 @@ expectDiagnostics' messageParser expected = do
103103 " but got " <> show actual
104104 go $ Map.delete (diagsNot ^. params . uri . to toNormalizedUri) m
105105
106−-- | Matches all diagnostic messages expect those from interface loading files
106+-- | Matches all diagnostic messages except those from interface loading files
107107diagnostic :: Session PublishDiagnosticsNotification
108108diagnostic = do
109109 m <- LspTest.message