Skip to content

Commit d4da724

Browse files
jhrcekmergify[bot]michaelpj
authored
Fix -Wall and -Wunused-packages in hls-alternate-number-format-plugin (#3964)
* Fix -Wunused-packages in hls-alternate-number-format-plugin * Fix -Wall warnings * Rename log to msg --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Michael Peyton Jones <me@michaelpj.com>
1 parent 7f4507c commit d4da724

File tree

5 files changed

+19
-28
lines changed

5 files changed

+19
-28
lines changed

plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +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.AlternateNumberFormat, Ide.Plugin.Conversion
2630
other-modules: Ide.Plugin.Literals
2731
hs-source-dirs: src
28-
ghc-options: -Wall
2932
build-depends:
30-
aeson
3133
, base >=4.12 && < 5
3234
, containers
3335
, extra
3436
, ghcide == 2.6.0.0
3537
, ghc-boot-th
3638
, hls-graph
3739
, hls-plugin-api == 2.6.0.0
38-
, hie-compat
3940
, lens
4041
, lsp ^>=2.3.0.0
4142
, mtl
4243
, regex-tdfa
4344
, syb
4445
, text
45-
, unordered-containers
4646

4747
default-language: Haskell2010
4848
default-extensions:
@@ -52,6 +52,7 @@ library
5252
RecordWildCards
5353

5454
test-suite tests
55+
import: warnings
5556
type: exitcode-stdio-1.0
5657
default-language: Haskell2010
5758
hs-source-dirs: test
@@ -63,8 +64,6 @@ test-suite tests
6364
, filepath
6465
, hls-alternate-number-format-plugin
6566
, hls-test-utils == 2.6.0.0
66-
, lsp
67-
, QuickCheck
6867
, regex-tdfa
6968
, tasty-quickcheck
7069
, text

plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ module Ide.Plugin.AlternateNumberFormat (descriptor, Log(..)) where
66

77
import Control.Lens ((^.))
88
import Control.Monad.Except (ExceptT)
9-
import Control.Monad.IO.Class (MonadIO, liftIO)
9+
import Control.Monad.IO.Class (MonadIO)
1010
import qualified Data.Map as Map
1111
import Data.Text (Text, unpack)
1212
import qualified Data.Text as T
1313
import Development.IDE (GetParsedModule (GetParsedModule),
1414
IdeState, RuleResult, Rules,
1515
define, realSrcSpanToRange,
16-
runAction, use)
16+
use)
1717
import Development.IDE.Core.PluginUtils
1818
import qualified Development.IDE.Core.Shake as Shake
1919
import Development.IDE.GHC.Compat hiding (getSrcSpan)
@@ -36,12 +36,11 @@ import qualified Language.LSP.Protocol.Lens as L
3636
import Language.LSP.Protocol.Message
3737
import Language.LSP.Protocol.Types
3838

39-
4039
newtype Log = LogShake Shake.Log deriving Show
4140

4241
instance Pretty Log where
4342
pretty = \case
44-
LogShake log -> pretty log
43+
LogShake msg -> pretty msg
4544

4645
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
4746
descriptor recorder pId = (defaultPluginDescriptor pId "Provides code actions to convert numeric literals to different formats")
@@ -93,7 +92,7 @@ codeActionHandler state pId (CodeActionParams _ _ docId currRange _) = do
9392
literalPairs = map (\lit -> (lit, alternateFormat lit)) litsInRange
9493
-- make a code action for every literal and its' alternates (then flatten the result)
9594
actions = concatMap (\(lit, alts) -> map (mkCodeAction nfp lit enabledExtensions pragma) alts) literalPairs
96-
pure $ InL $ actions
95+
pure $ InL actions
9796
where
9897
mkCodeAction :: NormalizedFilePath -> Literal -> [GhcExtension] -> NextPragmaInfo -> AlternateFormat -> Command |? CodeAction
9998
mkCodeAction nfp lit enabled npi af@(alt, ext) = InR CodeAction {

plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module Ide.Plugin.Conversion (
2121
, ExtensionNeeded(..)
2222
) where
2323

24-
import Data.Char (toUpper)
2524
import Data.List (delete)
2625
import Data.List.Extra (enumerate, upper)
2726
import Data.Maybe (mapMaybe)
@@ -168,10 +167,10 @@ toDecimal :: Integral a => a -> String
168167
toDecimal = toBase showInt ""
169168

170169
toBinary :: (Integral a, Show a) => a -> String
171-
toBinary = toBase showBin "0b"
170+
toBinary = toBase showBin_ "0b"
172171
where
173172
-- this is not defined in versions of Base < 4.16-ish
174-
showBin = showIntAtBase 2 intToDigit
173+
showBin_ = showIntAtBase 2 intToDigit
175174

176175
toHex :: (Integral a, Show a) => a -> String
177176
toHex = toBase showHex "0x"

plugins/hls-alternate-number-format-plugin/test/Main.hs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import Data.Text (Text)
99
import qualified Data.Text as T
1010
import qualified Ide.Plugin.AlternateNumberFormat as AlternateNumberFormat
1111
import qualified Ide.Plugin.Conversion as Conversion
12-
import Language.LSP.Protocol.Lens (kind)
13-
import Language.LSP.Protocol.Types (toEither)
1412
import Properties.Conversion (conversions)
1513
import System.FilePath ((<.>), (</>))
1614
import Test.Hls
@@ -110,21 +108,12 @@ codeActionTitle :: (Command |? CodeAction) -> Maybe Text
110108
codeActionTitle (InR CodeAction {_title}) = Just _title
111109
codeActionTitle _ = Nothing
112110

113-
codeActionTitle' :: CodeAction -> Text
114-
codeActionTitle' CodeAction{_title} = _title
115-
116111
pointRange :: Int -> Int -> Range
117112
pointRange
118113
(subtract 1 -> fromIntegral -> line)
119114
(subtract 1 -> fromIntegral -> col) =
120115
Range (Position line col) (Position line $ col + 1)
121116

122-
contains :: [CodeAction] -> Text -> Bool
123-
acts `contains` regex = any (\action -> codeActionTitle' action =~ regex) acts
124-
125-
doesNotContain :: [CodeAction] -> Text -> Bool
126-
acts `doesNotContain` regex = not $ acts `contains` regex
127-
128117
convertPrefix, intoInfix, maybeExtension, hexRegex, hexFloatRegex, binaryRegex, octalRegex, numDecimalRegex, decimalRegex :: Text
129118
convertPrefix = "Convert (" <> T.intercalate "|" [Conversion.hexRegex, Conversion.hexFloatRegex, Conversion.binaryRegex, Conversion.octalRegex, Conversion.numDecimalRegex, Conversion.decimalRegex] <> ")"
130119
intoInfix = " into "

plugins/hls-alternate-number-format-plugin/test/Properties/Conversion.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ import Test.Tasty.QuickCheck (testProperty)
77
import Text.Regex.TDFA ((=~))
88

99
conversions :: TestTree
10-
conversions = testGroup "Conversions" $ map (uncurry testProperty) [("Match NumDecimal", prop_regexMatchesNumDecimal)
10+
conversions = testGroup "Conversions" $
11+
map (uncurry testProperty)
12+
[ ("Match NumDecimal", prop_regexMatchesNumDecimal)
1113
, ("Match Hex", prop_regexMatchesHex)
1214
, ("Match Octal", prop_regexMatchesOctal)
1315
, ("Match Binary", prop_regexMatchesBinary)
14-
] <> map (uncurry testProperty) [("Match HexFloat", prop_regexMatchesHexFloat @Double)
16+
]
17+
<>
18+
map (uncurry testProperty)
19+
[ ("Match HexFloat", prop_regexMatchesHexFloat @Double)
1520
, ("Match FloatDecimal", prop_regexMatchesFloatDecimal)
1621
, ("Match FloatExpDecimal", prop_regexMatchesFloatExpDecimal)
1722
]
1823

1924
prop_regexMatchesNumDecimal :: Integer -> Bool
20-
prop_regexMatchesNumDecimal = (=~ numDecimalRegex) . toFloatExpDecimal . fromInteger
25+
prop_regexMatchesNumDecimal = (=~ numDecimalRegex) . toFloatExpDecimal @Double . fromInteger
2126

2227
prop_regexMatchesHex :: (Integral a, Show a) => a -> Bool
2328
prop_regexMatchesHex = (=~ hexRegex ) . toHex

0 commit comments

Comments
 (0)