on master help sign in
Merge pull request #59 from hsenag/unqualified-warnings

Make sure warnings use unqualified names where appropriate

commitd669f5306e7ef60047d474e99245157221b6f740 authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateSat 14 Sep 2019, 12:45 (7 years ago) parent4aa1821316d78a
2 files changed+21−2
src/Development/IDE/GHC/Warnings.hs+3−2 test/exe/Main.hs+18
src/Development/IDE/GHC/Warnings.hs+3−2
@@ -29,8 +29,9 @@ withWarnings :: GhcMonad m => T.Text -> ((ModSummary -> ModSummary) -> m a) -> m
2929withWarnings diagSource action = do
3030 warnings <- liftIO $ newVar []
3131 oldFlags <- getDynFlags
32− let newAction dynFlags _ _ loc _ msg = do
33− let d = diagFromErrMsg diagSource dynFlags $ mkPlainWarnMsg dynFlags loc msg
32+ let newAction :: DynFlags -> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
33+ newAction dynFlags _ _ loc style msg = do
34+ let d = diagFromErrMsg diagSource dynFlags $ mkWarnMsg dynFlags loc (queryQual style) msg
3435 modifyVar_ warnings $ return . (d:)
3536 setLogAction newAction
3637 res <- action $ \x -> x{ms_hspp_opts = (ms_hspp_opts x){log_action = newAction}}
test/exe/Main.hs+18
@@ -206,6 +206,24 @@ diagnosticTests = testGroup "diagnostics"
206206 ]
207207 )
208208 ]
209+ , testSession "unqualified warnings" $ do
210+ let fooContent = T.unlines
211+ [ "{-# OPTIONS_GHC -Wredundant-constraints #-}"
212+ , "module Foo where"
213+ , "foo :: Ord a => a -> Int"
214+ , "foo a = 1"
215+ ]
216+ _ <- openDoc' "Foo.hs" "haskell" fooContent
217+ expectDiagnostics
218+ [ ( "Foo.hs"
219+ -- The test is to make sure that warnings contain unqualified names
220+ -- where appropriate. The warning should use an unqualified name 'Ord', not
221+ -- sometihng like 'GHC.Classes.Ord'. The choice of redundant-constraints to
222+ -- test this is fairly arbitrary.
223+ , [(DsWarning, (2, 0), "Redundant constraint: Ord a")
224+ ]
225+ )
226+ ]
209227 ]
210228
211229codeActionTests :: TestTree