Skip to content

Fix -Wall and -Wunused-packages in hls-alternate-number-format-plugin #3964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ source-repository head
type: git
location: https://github.com/haskell/haskell-language-server.git

common warnings
ghc-options: -Wall -Wunused-packages

library
import: warnings
exposed-modules: Ide.Plugin.AlternateNumberFormat, Ide.Plugin.Conversion
other-modules: Ide.Plugin.Literals
hs-source-dirs: src
ghc-options: -Wall
build-depends:
aeson
, base >=4.12 && < 5
, containers
, extra
, ghcide == 2.6.0.0
, ghc-boot-th
, hls-graph
, hls-plugin-api == 2.6.0.0
, hie-compat
, lens
, lsp ^>=2.3.0.0
, mtl
, regex-tdfa
, syb
, text
, unordered-containers

default-language: Haskell2010
default-extensions:
Expand All @@ -52,6 +52,7 @@ library
RecordWildCards

test-suite tests
import: warnings
type: exitcode-stdio-1.0
default-language: Haskell2010
hs-source-dirs: test
Expand All @@ -63,8 +64,6 @@ test-suite tests
, filepath
, hls-alternate-number-format-plugin
, hls-test-utils == 2.6.0.0
, lsp
, QuickCheck
, regex-tdfa
, tasty-quickcheck
, text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ module Ide.Plugin.AlternateNumberFormat (descriptor, Log(..)) where

import Control.Lens ((^.))
import Control.Monad.Except (ExceptT)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.IO.Class (MonadIO)
import qualified Data.Map as Map
import Data.Text (Text, unpack)
import qualified Data.Text as T
import Development.IDE (GetParsedModule (GetParsedModule),
IdeState, RuleResult, Rules,
define, realSrcSpanToRange,
runAction, use)
use)
import Development.IDE.Core.PluginUtils
import qualified Development.IDE.Core.Shake as Shake
import Development.IDE.GHC.Compat hiding (getSrcSpan)
Expand All @@ -36,12 +36,11 @@ import qualified Language.LSP.Protocol.Lens as L
import Language.LSP.Protocol.Message
import Language.LSP.Protocol.Types


newtype Log = LogShake Shake.Log deriving Show

instance Pretty Log where
pretty = \case
LogShake log -> pretty log
LogShake msg -> pretty msg

descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
descriptor recorder pId = (defaultPluginDescriptor pId "Provides code actions to convert numeric literals to different formats")
Expand Down Expand Up @@ -93,7 +92,7 @@ codeActionHandler state pId (CodeActionParams _ _ docId currRange _) = do
literalPairs = map (\lit -> (lit, alternateFormat lit)) litsInRange
-- make a code action for every literal and its' alternates (then flatten the result)
actions = concatMap (\(lit, alts) -> map (mkCodeAction nfp lit enabledExtensions pragma) alts) literalPairs
pure $ InL $ actions
pure $ InL actions
where
mkCodeAction :: NormalizedFilePath -> Literal -> [GhcExtension] -> NextPragmaInfo -> AlternateFormat -> Command |? CodeAction
mkCodeAction nfp lit enabled npi af@(alt, ext) = InR CodeAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Ide.Plugin.Conversion (
, ExtensionNeeded(..)
) where

import Data.Char (toUpper)
import Data.List (delete)
import Data.List.Extra (enumerate, upper)
import Data.Maybe (mapMaybe)
Expand Down Expand Up @@ -168,10 +167,10 @@ toDecimal :: Integral a => a -> String
toDecimal = toBase showInt ""

toBinary :: (Integral a, Show a) => a -> String
toBinary = toBase showBin "0b"
toBinary = toBase showBin_ "0b"
where
-- this is not defined in versions of Base < 4.16-ish
showBin = showIntAtBase 2 intToDigit
showBin_ = showIntAtBase 2 intToDigit

toHex :: (Integral a, Show a) => a -> String
toHex = toBase showHex "0x"
Expand Down
11 changes: 0 additions & 11 deletions plugins/hls-alternate-number-format-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Data.Text (Text)
import qualified Data.Text as T
import qualified Ide.Plugin.AlternateNumberFormat as AlternateNumberFormat
import qualified Ide.Plugin.Conversion as Conversion
import Language.LSP.Protocol.Lens (kind)
import Language.LSP.Protocol.Types (toEither)
import Properties.Conversion (conversions)
import System.FilePath ((<.>), (</>))
import Test.Hls
Expand Down Expand Up @@ -110,21 +108,12 @@ codeActionTitle :: (Command |? CodeAction) -> Maybe Text
codeActionTitle (InR CodeAction {_title}) = Just _title
codeActionTitle _ = Nothing

codeActionTitle' :: CodeAction -> Text
codeActionTitle' CodeAction{_title} = _title

pointRange :: Int -> Int -> Range
pointRange
(subtract 1 -> fromIntegral -> line)
(subtract 1 -> fromIntegral -> col) =
Range (Position line col) (Position line $ col + 1)

contains :: [CodeAction] -> Text -> Bool
acts `contains` regex = any (\action -> codeActionTitle' action =~ regex) acts

doesNotContain :: [CodeAction] -> Text -> Bool
acts `doesNotContain` regex = not $ acts `contains` regex

convertPrefix, intoInfix, maybeExtension, hexRegex, hexFloatRegex, binaryRegex, octalRegex, numDecimalRegex, decimalRegex :: Text
convertPrefix = "Convert (" <> T.intercalate "|" [Conversion.hexRegex, Conversion.hexFloatRegex, Conversion.binaryRegex, Conversion.octalRegex, Conversion.numDecimalRegex, Conversion.decimalRegex] <> ")"
intoInfix = " into "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ import Test.Tasty.QuickCheck (testProperty)
import Text.Regex.TDFA ((=~))

conversions :: TestTree
conversions = testGroup "Conversions" $ map (uncurry testProperty) [("Match NumDecimal", prop_regexMatchesNumDecimal)
conversions = testGroup "Conversions" $
map (uncurry testProperty)
[ ("Match NumDecimal", prop_regexMatchesNumDecimal)
, ("Match Hex", prop_regexMatchesHex)
, ("Match Octal", prop_regexMatchesOctal)
, ("Match Binary", prop_regexMatchesBinary)
] <> map (uncurry testProperty) [("Match HexFloat", prop_regexMatchesHexFloat @Double)
]
<>
map (uncurry testProperty)
[ ("Match HexFloat", prop_regexMatchesHexFloat @Double)
, ("Match FloatDecimal", prop_regexMatchesFloatDecimal)
, ("Match FloatExpDecimal", prop_regexMatchesFloatExpDecimal)
]

prop_regexMatchesNumDecimal :: Integer -> Bool
prop_regexMatchesNumDecimal = (=~ numDecimalRegex) . toFloatExpDecimal . fromInteger
prop_regexMatchesNumDecimal = (=~ numDecimalRegex) . toFloatExpDecimal @Double . fromInteger

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