diff --git a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs index bc00c9b0a3..c993ae5cf0 100644 --- a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs +++ b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs @@ -81,10 +81,16 @@ suggest dflags diag = suggestDisableWarning :: Diagnostic -> [PragmaEdit] suggestDisableWarning Diagnostic {_code} - | Just (J.InR (T.stripPrefix "-W" -> Just w)) <- _code = + | Just (J.InR (T.stripPrefix "-W" -> Just w)) <- _code + , w `notElem` warningBlacklist = pure ("Disable \"" <> w <> "\" warnings", OptGHC w) | otherwise = [] +-- Don't suggest disabling type errors as a solution to all type errors +warningBlacklist :: [T.Text] +-- warningBlacklist = [] +warningBlacklist = ["deferred-type-errors"] + -- --------------------------------------------------------------------- -- | Offer to add a missing Language Pragma to the top of a file. diff --git a/plugins/hls-pragmas-plugin/test/Main.hs b/plugins/hls-pragmas-plugin/test/Main.hs index d9af4bbc0f..b48591dda2 100644 --- a/plugins/hls-pragmas-plugin/test/Main.hs +++ b/plugins/hls-pragmas-plugin/test/Main.hs @@ -123,6 +123,13 @@ codeActionTests = cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Disable \"unused-imports\" warnings" `elem` map (^. L.title) cas @? "Contains unused-imports code action" executeCodeAction $ head cas + + , goldenWithPragmas "doesn't suggest disabling type errors" "DeferredTypeErrors" $ \doc -> do + + _ <- waitForDiagnosticsFrom doc + cas <- map fromAction <$> getAllCodeActions doc + liftIO $ "Disable \"deferred-type-errors\" warnings" `notElem` map (^. L.title) cas @? "Doesn't contain deferred-type-errors code action" + liftIO $ length cas == 0 @? "Expected no code actions, but got: " <> show cas ] completionTests :: TestTree diff --git a/plugins/hls-pragmas-plugin/test/testdata/DeferredTypeErrors.expected.hs b/plugins/hls-pragmas-plugin/test/testdata/DeferredTypeErrors.expected.hs new file mode 100644 index 0000000000..a0e2fd6162 --- /dev/null +++ b/plugins/hls-pragmas-plugin/test/testdata/DeferredTypeErrors.expected.hs @@ -0,0 +1,4 @@ +module DeferredTypeErrors where + +foo :: Int +foo = () diff --git a/plugins/hls-pragmas-plugin/test/testdata/DeferredTypeErrors.hs b/plugins/hls-pragmas-plugin/test/testdata/DeferredTypeErrors.hs new file mode 100644 index 0000000000..a0e2fd6162 --- /dev/null +++ b/plugins/hls-pragmas-plugin/test/testdata/DeferredTypeErrors.hs @@ -0,0 +1,4 @@ +module DeferredTypeErrors where + +foo :: Int +foo = ()