Skip to content

Commit 8891c27

Browse files
authored
Merge branch 'master' into brittany-package
2 parents 05724c4 + 1c45629 commit 8891c27

File tree

5 files changed

+195
-188
lines changed

5 files changed

+195
-188
lines changed

ghcide/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ suggestAction packageExports ideOptions parsedModule text df annSource tcM har d
158158
++ suggestNewImport packageExports pm diag
159159
++ suggestDeleteUnusedBinding pm text diag
160160
++ suggestExportUnusedTopBinding text pm diag
161-
++ suggestDisableWarning pm text diag
162161
| Just pm <- [parsedModule]
163162
] ++
164163
suggestFillHole diag -- Lowest priority
@@ -257,15 +256,6 @@ isUnusedImportedId
257256
maybe True (not . any (\(_, IdentifierDetails {..}) -> identInfo == S.singleton Use)) refs
258257
| otherwise = False
259258

260-
suggestDisableWarning :: ParsedModule -> Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
261-
suggestDisableWarning pm contents Diagnostic{..}
262-
| Just (InR (T.stripPrefix "-W" -> Just w)) <- _code =
263-
pure
264-
( "Disable \"" <> w <> "\" warnings"
265-
, [TextEdit (endOfModuleHeader pm contents) $ "{-# OPTIONS_GHC -Wno-" <> w <> " #-}\n"]
266-
)
267-
| otherwise = []
268-
269259
suggestRemoveRedundantImport :: ParsedModule -> Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
270260
suggestRemoveRedundantImport ParsedModule{pm_parsed_source = L _ HsModule{hsmodImports}} contents Diagnostic{_range=_range,..}
271261
-- The qualified import of ‘many’ from module ‘Control.Applicative’ is redundant
@@ -1452,16 +1442,3 @@ renderImportStyle :: ImportStyle -> T.Text
14521442
renderImportStyle (ImportTopLevel x) = x
14531443
renderImportStyle (ImportViaParent x p) = p <> "(" <> x <> ")"
14541444

1455-
-- | Find the first non-blank line before the first of (module name / imports / declarations).
1456-
-- Useful for inserting pragmas.
1457-
endOfModuleHeader :: ParsedModule -> Maybe T.Text -> Range
1458-
endOfModuleHeader pm contents =
1459-
let mod = unLoc $ pm_parsed_source pm
1460-
modNameLoc = getLoc <$> hsmodName mod
1461-
firstImportLoc = getLoc <$> listToMaybe (hsmodImports mod)
1462-
firstDeclLoc = getLoc <$> listToMaybe (hsmodDecls mod)
1463-
line = fromMaybe 0 $ firstNonBlankBefore . _line . _start =<< srcSpanToRange =<<
1464-
modNameLoc <|> firstImportLoc <|> firstDeclLoc
1465-
firstNonBlankBefore n = (n -) . fromMaybe 0 . findIndex (not . T.null) . reverse . take n . T.lines <$> contents
1466-
loc = Position line 0
1467-
in Range loc loc

ghcide/test/exe/Main.hs

Lines changed: 27 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ import Development.IDE.Plugin.Test (TestRequest (BlockSeconds, GetInterfaceFiles
8181
import Control.Monad.Extra (whenJust)
8282
import qualified Language.LSP.Types.Lens as L
8383
import Control.Lens ((^.))
84-
import Data.Functor
8584
import Data.Tuple.Extra
8685

8786
waitForProgressBegin :: Session ()
@@ -706,7 +705,6 @@ codeActionTests = testGroup "code actions"
706705
, suggestImportTests
707706
, suggestHideShadowTests
708707
, suggestImportDisambiguationTests
709-
, disableWarningTests
710708
, fixConstructorImportTests
711709
, importRenameActionTests
712710
, fillTypedHoleTests
@@ -913,8 +911,9 @@ removeImportTests = testGroup "remove import actions"
913911
]
914912
docB <- createDoc "ModuleB.hs" "haskell" contentB
915913
_ <- waitForDiagnostics
916-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove import")
917-
=<< getCodeActions docB (Range (Position 2 0) (Position 2 5))
914+
[InR action@CodeAction { _title = actionTitle }, _]
915+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
916+
liftIO $ "Remove import" @=? actionTitle
918917
executeCodeAction action
919918
contentAfterAction <- documentContents docB
920919
let expectedContentAfterAction = T.unlines
@@ -938,8 +937,9 @@ removeImportTests = testGroup "remove import actions"
938937
]
939938
docB <- createDoc "ModuleB.hs" "haskell" contentB
940939
_ <- waitForDiagnostics
941-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove import")
942-
=<< getCodeActions docB (Range (Position 2 0) (Position 2 5))
940+
[InR action@CodeAction { _title = actionTitle }, _]
941+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
942+
liftIO $ "Remove import" @=? actionTitle
943943
executeCodeAction action
944944
contentAfterAction <- documentContents docB
945945
let expectedContentAfterAction = T.unlines
@@ -966,8 +966,9 @@ removeImportTests = testGroup "remove import actions"
966966
]
967967
docB <- createDoc "ModuleB.hs" "haskell" contentB
968968
_ <- waitForDiagnostics
969-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove stuffA, stuffC from import")
970-
=<< getCodeActions docB (Range (Position 2 0) (Position 2 5))
969+
[InR action@CodeAction { _title = actionTitle }, _]
970+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
971+
liftIO $ "Remove stuffA, stuffC from import" @=? actionTitle
971972
executeCodeAction action
972973
contentAfterAction <- documentContents docB
973974
let expectedContentAfterAction = T.unlines
@@ -994,8 +995,9 @@ removeImportTests = testGroup "remove import actions"
994995
]
995996
docB <- createDoc "ModuleB.hs" "haskell" contentB
996997
_ <- waitForDiagnostics
997-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove !!, <?> from import")
998-
=<< getCodeActions docB (Range (Position 2 0) (Position 2 5))
998+
[InR action@CodeAction { _title = actionTitle }, _]
999+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
1000+
liftIO $ "Remove !!, <?> from import" @=? actionTitle
9991001
executeCodeAction action
10001002
contentAfterAction <- documentContents docB
10011003
let expectedContentAfterAction = T.unlines
@@ -1021,8 +1023,9 @@ removeImportTests = testGroup "remove import actions"
10211023
]
10221024
docB <- createDoc "ModuleB.hs" "haskell" contentB
10231025
_ <- waitForDiagnostics
1024-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove A from import")
1025-
=<< getCodeActions docB (Range (Position 2 0) (Position 2 5))
1026+
[InR action@CodeAction { _title = actionTitle }, _]
1027+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
1028+
liftIO $ "Remove A from import" @=? actionTitle
10261029
executeCodeAction action
10271030
contentAfterAction <- documentContents docB
10281031
let expectedContentAfterAction = T.unlines
@@ -1047,8 +1050,9 @@ removeImportTests = testGroup "remove import actions"
10471050
]
10481051
docB <- createDoc "ModuleB.hs" "haskell" contentB
10491052
_ <- waitForDiagnostics
1050-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove A, E, F from import")
1051-
=<< getCodeActions docB (Range (Position 2 0) (Position 2 5))
1053+
[InR action@CodeAction { _title = actionTitle }, _]
1054+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
1055+
liftIO $ "Remove A, E, F from import" @=? actionTitle
10521056
executeCodeAction action
10531057
contentAfterAction <- documentContents docB
10541058
let expectedContentAfterAction = T.unlines
@@ -1070,8 +1074,9 @@ removeImportTests = testGroup "remove import actions"
10701074
]
10711075
docB <- createDoc "ModuleB.hs" "haskell" contentB
10721076
_ <- waitForDiagnostics
1073-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove import")
1074-
=<< getCodeActions docB (Range (Position 2 0) (Position 2 5))
1077+
[InR action@CodeAction { _title = actionTitle }, _]
1078+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
1079+
liftIO $ "Remove import" @=? actionTitle
10751080
executeCodeAction action
10761081
contentAfterAction <- documentContents docB
10771082
let expectedContentAfterAction = T.unlines
@@ -1094,8 +1099,9 @@ removeImportTests = testGroup "remove import actions"
10941099
]
10951100
doc <- createDoc "ModuleC.hs" "haskell" content
10961101
_ <- waitForDiagnostics
1097-
action <- assertJust "Code action not found" . firstJust (caWithTitle "Remove all redundant imports")
1098-
=<< getCodeActions doc (Range (Position 2 0) (Position 2 5))
1102+
[_, _, _, _, InR action@CodeAction { _title = actionTitle }]
1103+
<- getCodeActions doc (Range (Position 2 0) (Position 2 5))
1104+
liftIO $ "Remove all redundant imports" @=? actionTitle
10991105
executeCodeAction action
11001106
contentAfterAction <- documentContents doc
11011107
let expectedContentAfterAction = T.unlines
@@ -1111,10 +1117,6 @@ removeImportTests = testGroup "remove import actions"
11111117
]
11121118
liftIO $ expectedContentAfterAction @=? contentAfterAction
11131119
]
1114-
where
1115-
caWithTitle t = \case
1116-
InR a@CodeAction{_title} -> guard (_title == t) >> Just a
1117-
_ -> Nothing
11181120

11191121
extendImportTests :: TestTree
11201122
extendImportTests = testGroup "extend import actions"
@@ -1784,57 +1786,6 @@ suggestHideShadowTests =
17841786
, "(++) = id"
17851787
]
17861788

1787-
disableWarningTests :: TestTree
1788-
disableWarningTests =
1789-
testGroup "disable warnings" $
1790-
[
1791-
( "missing-signatures"
1792-
, T.unlines
1793-
[ "{-# OPTIONS_GHC -Wall #-}"
1794-
, "main = putStrLn \"hello\""
1795-
]
1796-
, T.unlines
1797-
[ "{-# OPTIONS_GHC -Wall #-}"
1798-
, "{-# OPTIONS_GHC -Wno-missing-signatures #-}"
1799-
, "main = putStrLn \"hello\""
1800-
]
1801-
)
1802-
,
1803-
( "unused-imports"
1804-
, T.unlines
1805-
[ "{-# OPTIONS_GHC -Wall #-}"
1806-
, ""
1807-
, ""
1808-
, "module M where"
1809-
, ""
1810-
, "import Data.Functor"
1811-
]
1812-
, T.unlines
1813-
[ "{-# OPTIONS_GHC -Wall #-}"
1814-
, "{-# OPTIONS_GHC -Wno-unused-imports #-}"
1815-
, ""
1816-
, ""
1817-
, "module M where"
1818-
, ""
1819-
, "import Data.Functor"
1820-
]
1821-
)
1822-
]
1823-
<&> \(warning, initialContent, expectedContent) -> testSession (T.unpack warning) $ do
1824-
doc <- createDoc "Module.hs" "haskell" initialContent
1825-
_ <- waitForDiagnostics
1826-
codeActs <- mapMaybe caResultToCodeAct <$> getCodeActions doc (Range (Position 0 0) (Position 0 0))
1827-
case find (\CodeAction{_title} -> _title == "Disable \"" <> warning <> "\" warnings") codeActs of
1828-
Nothing -> liftIO $ assertFailure "No code action with expected title"
1829-
Just action -> do
1830-
executeCodeAction action
1831-
contentAfterAction <- documentContents doc
1832-
liftIO $ expectedContent @=? contentAfterAction
1833-
where
1834-
caResultToCodeAct = \case
1835-
InL _ -> Nothing
1836-
InR c -> Just c
1837-
18381789
insertNewDefinitionTests :: TestTree
18391790
insertNewDefinitionTests = testGroup "insert new definition actions"
18401791
[ testSession "insert new function definition" $ do
@@ -2586,12 +2537,7 @@ removeRedundantConstraintsTests = let
25862537
doc <- createDoc "Testing.hs" "haskell" code
25872538
_ <- waitForDiagnostics
25882539
actionsOrCommands <- getCodeActions doc (Range (Position 4 0) (Position 4 maxBound))
2589-
liftIO $ assertBool "Found some actions (other than \"disable warnings\")"
2590-
$ all isDisableWarningAction actionsOrCommands
2591-
where
2592-
isDisableWarningAction = \case
2593-
InR CodeAction{_title} -> "Disable" `T.isPrefixOf` _title && "warnings" `T.isSuffixOf` _title
2594-
_ -> False
2540+
liftIO $ assertBool "Found some actions" (null actionsOrCommands)
25952541

25962542
in testGroup "remove redundant function constraints"
25972543
[ check
@@ -4786,9 +4732,7 @@ asyncTests = testGroup "async"
47864732
void waitForDiagnostics
47874733
actions <- getCodeActions doc (Range (Position 1 0) (Position 1 0))
47884734
liftIO $ [ _title | InR CodeAction{_title} <- actions] @=?
4789-
[ "add signature: foo :: a -> a"
4790-
, "Disable \"missing-signatures\" warnings"
4791-
]
4735+
[ "add signature: foo :: a -> a" ]
47924736
, testSession "request" $ do
47934737
-- Execute a custom request that will block for 1000 seconds
47944738
void $ sendRequest (SCustomMethod "test") $ toJSON $ BlockSeconds 1000
@@ -4800,9 +4744,7 @@ asyncTests = testGroup "async"
48004744
void waitForDiagnostics
48014745
actions <- getCodeActions doc (Range (Position 0 0) (Position 0 0))
48024746
liftIO $ [ _title | InR CodeAction{_title} <- actions] @=?
4803-
[ "add signature: foo :: a -> a"
4804-
, "Disable \"missing-signatures\" warnings"
4805-
]
4747+
[ "add signature: foo :: a -> a" ]
48064748
]
48074749

48084750

0 commit comments

Comments
 (0)