Skip to content

Commit 866a533

Browse files
authored
Fix -Wall and -Wunused-packages in pragmas plugin (#3982)
1 parent 6620f2c commit 866a533

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

plugins/hls-pragmas-plugin/hls-pragmas-plugin.cabal

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@ source-repository head
2121
type: git
2222
location: https://github.com/haskell/haskell-language-server.git
2323

24+
common warnings
25+
ghc-options: -Wall -Wunused-packages
26+
2427
library
28+
import: warnings
2529
exposed-modules: Ide.Plugin.Pragmas
2630
hs-source-dirs: src
2731
build-depends:
2832
, base >=4.12 && <5
2933
, extra
3034
, fuzzy
31-
, ghc
3235
, ghcide == 2.6.0.0
3336
, hls-plugin-api == 2.6.0.0
3437
, lens
3538
, lsp
3639
, text
3740
, transformers
38-
, unordered-containers
3941
, containers
40-
ghc-options: -Wall -Wno-name-shadowing
4142
default-language: Haskell2010
4243

4344
test-suite tests
45+
import: warnings
4446
type: exitcode-stdio-1.0
4547
default-language: Haskell2010
4648
hs-source-dirs: test

plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import Control.Monad.IO.Class (MonadIO (liftIO))
2222
import Control.Monad.Trans.Class (lift)
2323
import Data.List.Extra (nubOrdOn)
2424
import qualified Data.Map as M
25-
import Data.Maybe (catMaybes)
25+
import Data.Maybe (mapMaybe)
2626
import qualified Data.Text as T
27-
import Development.IDE
27+
import Development.IDE hiding (line)
2828
import Development.IDE.Core.Compile (sourceParser,
2929
sourceTypecheck)
3030
import Development.IDE.Core.PluginUtils
@@ -85,7 +85,7 @@ mkCodeActionProvider mkSuggest state _plId
8585
parsedModule <- liftIO $ runAction "Pragmas.GetParsedModule" state $ getParsedModule normalizedFilePath
8686
let parsedModuleDynFlags = ms_hspp_opts . pm_mod_summary <$> parsedModule
8787
nextPragmaInfo = Pragmas.getNextPragmaInfo sessionDynFlags fileContents
88-
pedits = (nubOrdOn snd . concat $ mkSuggest parsedModuleDynFlags <$> diags)
88+
pedits = nubOrdOn snd $ concatMap (mkSuggest parsedModuleDynFlags) diags
8989
pure $ LSP.InL $ pragmaEditToAction uri nextPragmaInfo <$> pedits
9090

9191

@@ -146,7 +146,7 @@ suggestAddPragma mDynflags Diagnostic {_message, _source}
146146
disabled
147147
| Just dynFlags <- mDynflags =
148148
-- GHC does not export 'OnOff', so we have to view it as string
149-
catMaybes $ T.stripPrefix "Off " . printOutputable <$> extensions dynFlags
149+
mapMaybe (T.stripPrefix "Off " . printOutputable) (extensions dynFlags)
150150
| otherwise =
151151
-- When the module failed to parse, we don't have access to its
152152
-- dynFlags. In that case, simply don't disable any pragmas.
@@ -201,7 +201,7 @@ completion _ide _ complParams = do
201201
let (LSP.TextDocumentIdentifier uri) = complParams ^. L.textDocument
202202
position = complParams ^. L.position
203203
contents <- lift $ LSP.getVirtualFile $ toNormalizedUri uri
204-
fmap (LSP.InL) $ case (contents, uriToFilePath' uri) of
204+
fmap LSP.InL $ case (contents, uriToFilePath' uri) of
205205
(Just cnts, Just _path) ->
206206
result <$> VFS.getCompletionPrefix position cnts
207207
where
@@ -252,7 +252,7 @@ completion _ide _ complParams = do
252252
| "}" `T.isSuffixOf` line = " #-"
253253
| otherwise = " #-}"
254254
result Nothing = []
255-
_ -> return $ []
255+
_ -> return []
256256

257257
-----------------------------------------------------------------------
258258

plugins/hls-pragmas-plugin/test/Main.hs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
2+
33
module Main
44
( main
55
) where
@@ -12,7 +12,6 @@ import Ide.Plugin.Pragmas
1212
import qualified Language.LSP.Protocol.Lens as L
1313
import System.FilePath
1414
import Test.Hls
15-
import Test.Hls.Util (onlyWorkForGhcVersions)
1615

1716
main :: IO ()
1817
main = defaultTestRunner tests
@@ -80,9 +79,6 @@ codeActionTests =
8079
, codeActionTestWithDisableWarning "before doc comments" "UnusedImports" [("Disable \"unused-imports\" warnings", "Contains unused-imports code action")]
8180
]
8281

83-
ghc94regression :: String
84-
ghc94regression = "to be reported"
85-
8682
codeActionTestWithPragmasSuggest :: String -> FilePath -> [(T.Text, String)] -> TestTree
8783
codeActionTestWithPragmasSuggest = codeActionTestWith pragmasSuggestPlugin
8884

@@ -105,8 +101,7 @@ codeActionTestWith descriptor testComment fp actions =
105101
codeActionTests' :: TestTree
106102
codeActionTests' =
107103
testGroup "additional code actions"
108-
[
109-
goldenWithPragmas pragmasSuggestPlugin "no duplication" "NamedFieldPuns" $ \doc -> do
104+
[ goldenWithPragmas pragmasSuggestPlugin "no duplication" "NamedFieldPuns" $ \doc -> do
110105
_ <- waitForDiagnosticsFrom doc
111106
cas <- map fromAction <$> getCodeActions doc (Range (Position 8 9) (Position 8 9))
112107
ca <- liftIO $ case cas of
@@ -124,18 +119,17 @@ codeActionTests' =
124119
completionTests :: TestTree
125120
completionTests =
126121
testGroup "completions"
127-
[ completionTest "completes pragmas" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension} #-}") (Just "{-# LANGUAGE #-}") [0, 4, 0, 34, 0, 4]
128-
, completionTest "completes pragmas with existing closing pragma bracket" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension}") (Just "{-# LANGUAGE #-}") [0, 4, 0, 31, 0, 4]
129-
, completionTest "completes pragmas with existing closing comment bracket" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension} #") (Just "{-# LANGUAGE #-}") [0, 4, 0, 32, 0, 4]
130-
, completionTest "completes pragmas with existing closing bracket" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension} #-") (Just "{-# LANGUAGE #-}") [0, 4, 0, 33, 0, 4]
131-
, completionTest "completes options pragma" "Completion.hs" "OPTIONS" "OPTIONS_GHC" (Just InsertTextFormat_Snippet) (Just "OPTIONS_GHC -${1:option} #-}") (Just "{-# OPTIONS_GHC #-}") [0, 4, 0, 34, 0, 4]
132-
, completionTest "completes ghc options pragma values" "Completion.hs" "{-# OPTIONS_GHC -Wno-red #-}\n" "Wno-redundant-constraints" Nothing Nothing Nothing [0, 0, 0, 0, 0, 24]
133-
, completionTest "completes language extensions" "Completion.hs" "" "OverloadedStrings" Nothing Nothing Nothing [0, 24, 0, 31, 0, 24]
134-
, completionTest "completes language extensions case insensitive" "Completion.hs" "lAnGuaGe Overloaded" "OverloadedStrings" Nothing Nothing Nothing [0, 4, 0, 34, 0, 24]
135-
, completionTest "completes the Strict language extension" "Completion.hs" "Str" "Strict" Nothing Nothing Nothing [0, 13, 0, 31, 0, 16]
136-
, completionTest "completes No- language extensions" "Completion.hs" "NoOverload" "NoOverloadedStrings" Nothing Nothing Nothing [0, 13, 0, 31, 0, 23]
137-
, onlyWorkForGhcVersions (>=GHC92) "GHC2021 flag introduced since ghc9.2" $
138-
completionTest "completes GHC2021 extensions" "Completion.hs" "ghc" "GHC2021" Nothing Nothing Nothing [0, 13, 0, 31, 0, 16]
122+
[ completionTest "completes pragmas" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension} #-}") (Just "{-# LANGUAGE #-}") (0, 4, 0, 34, 0, 4)
123+
, completionTest "completes pragmas with existing closing pragma bracket" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension}") (Just "{-# LANGUAGE #-}") (0, 4, 0, 31, 0, 4)
124+
, completionTest "completes pragmas with existing closing comment bracket" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension} #") (Just "{-# LANGUAGE #-}") (0, 4, 0, 32, 0, 4)
125+
, completionTest "completes pragmas with existing closing bracket" "Completion.hs" "" "LANGUAGE" (Just InsertTextFormat_Snippet) (Just "LANGUAGE ${1:extension} #-") (Just "{-# LANGUAGE #-}") (0, 4, 0, 33, 0, 4)
126+
, completionTest "completes options pragma" "Completion.hs" "OPTIONS" "OPTIONS_GHC" (Just InsertTextFormat_Snippet) (Just "OPTIONS_GHC -${1:option} #-}") (Just "{-# OPTIONS_GHC #-}") (0, 4, 0, 34, 0, 4)
127+
, completionTest "completes ghc options pragma values" "Completion.hs" "{-# OPTIONS_GHC -Wno-red #-}\n" "Wno-redundant-constraints" Nothing Nothing Nothing (0, 0, 0, 0, 0, 24)
128+
, completionTest "completes language extensions" "Completion.hs" "" "OverloadedStrings" Nothing Nothing Nothing (0, 24, 0, 31, 0, 24)
129+
, completionTest "completes language extensions case insensitive" "Completion.hs" "lAnGuaGe Overloaded" "OverloadedStrings" Nothing Nothing Nothing (0, 4, 0, 34, 0, 24)
130+
, completionTest "completes the Strict language extension" "Completion.hs" "Str" "Strict" Nothing Nothing Nothing (0, 13, 0, 31, 0, 16)
131+
, completionTest "completes No- language extensions" "Completion.hs" "NoOverload" "NoOverloadedStrings" Nothing Nothing Nothing (0, 13, 0, 31, 0, 23)
132+
, completionTest "completes GHC2021 extensions" "Completion.hs" "ghc" "GHC2021" Nothing Nothing Nothing (0, 13, 0, 31, 0, 16)
139133
]
140134

141135
completionSnippetTests :: TestTree
@@ -151,7 +145,7 @@ completionSnippetTests =
151145
in completionTest (T.unpack label)
152146
"Completion.hs" input label (Just InsertTextFormat_Snippet)
153147
(Just $ "{-# " <> insertText <> " #-}") (Just detail)
154-
[0, 0, 0, 34, 0, fromIntegral $ T.length input])
148+
(0, 0, 0, 34, 0, fromIntegral $ T.length input))
155149

156150
dontSuggestCompletionTests :: TestTree
157151
dontSuggestCompletionTests =
@@ -162,7 +156,7 @@ dontSuggestCompletionTests =
162156
, provideNoCompletionsTest "when no word has been typed" "Completion.hs" Nothing (Position 3 0)
163157
, provideNoCompletionsTest "when expecting auto complete on modules" "Completion.hs" (Just $ mkEdit (8,6) (8,8) "Data.Maybe.WA") (Position 8 19)
164158
]
165-
individualPragmaTests = validPragmas <&> \(insertText,label,detail,appearWhere) ->
159+
individualPragmaTests = validPragmas <&> \(_insertText,label,_detail,appearWhere) ->
166160
let completionPrompt = T.toLower $ T.init label
167161
promptLen = fromIntegral (T.length completionPrompt)
168162
in case appearWhere of
@@ -176,8 +170,8 @@ mkEdit :: (UInt,UInt) -> (UInt,UInt) -> T.Text -> TextEdit
176170
mkEdit (startLine, startCol) (endLine, endCol) newText =
177171
TextEdit (Range (Position startLine startCol) (Position endLine endCol)) newText
178172

179-
completionTest :: String -> FilePath -> T.Text -> T.Text -> Maybe InsertTextFormat -> Maybe T.Text -> Maybe T.Text -> [UInt] -> TestTree
180-
completionTest testComment fileName replacementText expectedLabel expectedFormat expectedInsertText detail [delFromLine, delFromCol, delToLine, delToCol, completeAtLine, completeAtCol] =
173+
completionTest :: String -> FilePath -> T.Text -> T.Text -> Maybe InsertTextFormat -> Maybe T.Text -> Maybe T.Text -> (UInt, UInt, UInt, UInt, UInt, UInt) -> TestTree
174+
completionTest testComment fileName replacementText expectedLabel expectedFormat expectedInsertText detail (delFromLine, delFromCol, delToLine, delToCol, completeAtLine, completeAtCol) =
181175
testCase testComment $ runSessionWithServer def pragmasCompletionPlugin testDataDir $ do
182176
doc <- openDoc fileName "haskell"
183177
_ <- waitForDiagnostics

0 commit comments

Comments
 (0)