Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GHCi specific hints from GHC error messages #150

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/GHC/Diagnostic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data Severity = Warning | Error
deriving (Eq, Show, Generic, ToJSON, FromJSON)

parse :: ByteString -> Maybe Diagnostic
parse = decode . fromStrict
parse = fmap removeGhciSpecificHints . decode . fromStrict

format :: Diagnostic -> ByteString
format diagnostic = encodeUtf8 . render $ unlines [
Expand Down Expand Up @@ -90,3 +90,11 @@ format diagnostic = encodeUtf8 . render $ unlines [

unlines :: [Doc] -> Doc
unlines = foldr ($+$) empty

removeGhciSpecificHints :: Diagnostic -> Diagnostic
removeGhciSpecificHints diagnostic = diagnostic { hints = map f diagnostic.hints }
where
f :: String -> String
f input = case lines input of
[hint, "You may enable this language extension in GHCi with:", ghciHint] | " :set -X" `isPrefixOf` ghciHint -> hint
_ -> input
2 changes: 1 addition & 1 deletion test/GHC/DiagnosticSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import GHC.Diagnostic
test :: HasCallStack => FilePath -> Spec
test name = it name $ do
err <- translate <$> ghc ["-fno-diagnostics-show-caret"]
json <- encodeUtf8 <$> ghc ["-fdiagnostics-as-json"]
json <- encodeUtf8 <$> ghc ["-fdiagnostics-as-json", "--interactive", "-ignore-dot-ghci"]
ensureFile (dir </> "err.out") (encodeUtf8 err)
ensureFile (dir </> "err.json") json
Just diagnostic <- return $ parse json
Expand Down
2 changes: 1 addition & 1 deletion test/assets/use-BlockArguments/err.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.0","ghcVersion":"ghc-9.10.1","span":{"file":"test/assets/use-BlockArguments/Foo.hs","start":{"line":5,"column":10},"end":{"line":5,"column":22}},"severity":"Error","code":52095,"message":["Unexpected do block in function application:\n do return ()"],"hints":["Use parentheses.","Perhaps you intended to use BlockArguments"]}
{"version":"1.0","ghcVersion":"ghc-9.10.1","span":{"file":"test/assets/use-BlockArguments/Foo.hs","start":{"line":5,"column":10},"end":{"line":5,"column":22}},"severity":"Error","code":52095,"message":["Unexpected do block in function application:\n do return ()"],"hints":["Use parentheses.","Perhaps you intended to use BlockArguments\nYou may enable this language extension in GHCi with:\n :set -XBlockArguments"]}
Loading