Skip to content

Commit c7c3982

Browse files
authored
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
1 parent 07cf929 commit c7c3982

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/Development/IDE/GHC/Error.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ diagFromText diagSource sev loc msg = (toNormalizedFilePath' $ srcSpanToFilename
5656
-- | Produce a GHC-style error from a source span and a message.
5757
diagFromErrMsg :: T.Text -> DynFlags -> ErrMsg -> [FileDiagnostic]
5858
diagFromErrMsg 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
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Main (main) where
1111

1212
import Control.Applicative.Combinators
1313
import Control.Exception (catch)
14+
import qualified Control.Lens as Lens
1415
import Control.Monad
1516
import Control.Monad.IO.Class (liftIO)
1617
import Data.Aeson (FromJSON, Value)
@@ -32,6 +33,7 @@ import Language.Haskell.LSP.Test hiding (openDoc')
3233
import Language.Haskell.LSP.Messages
3334
import Language.Haskell.LSP.Types
3435
import Language.Haskell.LSP.Types.Capabilities
36+
import qualified Language.Haskell.LSP.Types.Lens as Lsp (diagnostics, params, message)
3537
import Language.Haskell.LSP.VFS (applyChange)
3638
import Network.URI
3739
import 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

438458
codeActionTests :: 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
Original file line numberDiff line numberDiff line change
@@ -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
107107
diagnostic :: Session PublishDiagnosticsNotification
108108
diagnostic = do
109109
m <- LspTest.message

0 commit comments

Comments
 (0)