diff --git a/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal b/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal index df9673482d..01bbdcb214 100644 --- a/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal +++ b/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal @@ -21,13 +21,15 @@ 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 @@ -35,14 +37,12 @@ library , 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: @@ -52,6 +52,7 @@ library RecordWildCards test-suite tests + import: warnings type: exitcode-stdio-1.0 default-language: Haskell2010 hs-source-dirs: test @@ -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 diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs index ee2e489371..b06414f528 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs @@ -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) @@ -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") @@ -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 { diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs index a6872121af..2ca10a6749 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs @@ -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) @@ -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" diff --git a/plugins/hls-alternate-number-format-plugin/test/Main.hs b/plugins/hls-alternate-number-format-plugin/test/Main.hs index 6eedae82ce..323a5f0618 100644 --- a/plugins/hls-alternate-number-format-plugin/test/Main.hs +++ b/plugins/hls-alternate-number-format-plugin/test/Main.hs @@ -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 @@ -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 " diff --git a/plugins/hls-alternate-number-format-plugin/test/Properties/Conversion.hs b/plugins/hls-alternate-number-format-plugin/test/Properties/Conversion.hs index a1a1dfe660..bc95e0f51c 100644 --- a/plugins/hls-alternate-number-format-plugin/test/Properties/Conversion.hs +++ b/plugins/hls-alternate-number-format-plugin/test/Properties/Conversion.hs @@ -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