Skip to content

Commit

Permalink
Don't suggest disabling type errors (#2061)
Browse files Browse the repository at this point in the history
* Add a failing test for #2032

* Don't suggest -Wno-deferred-type-errors

Fixes #2032
  • Loading branch information
anka-213 authored Aug 2, 2021
1 parent 2fef041 commit 047ffc3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions plugins/hls-pragmas-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module DeferredTypeErrors where

foo :: Int
foo = ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module DeferredTypeErrors where

foo :: Int
foo = ()

0 comments on commit 047ffc3

Please sign in to comment.