diff --git a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal index b0910a071c..c1b4ed1974 100644 --- a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal +++ b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal @@ -32,7 +32,7 @@ library build-depends: , base >=4.12 && <5 , filepath - , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 || ^>= 0.8 || ^>= 0.9 || ^>= 0.10 || ^>= 0.11 || ^>= 0.12 + , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 || ^>= 0.8 || ^>= 0.9 || ^>= 0.10 || ^>= 0.11 || ^>= 0.12 || ^>= 0.13 , ghc , ghc-boot-th , ghcide == 2.1.0.0 diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index b6b46f2426..3ae5baf1bc 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -24,6 +24,7 @@ import Control.Monad.Trans.Except (ExceptT (..), mapExceptT, import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.Trans.Class (MonadTrans (lift)) import Data.Bifunctor (bimap) +import Data.List (intercalate) import Data.Maybe (catMaybes) import Data.Text (Text) import qualified Data.Text as T @@ -75,6 +76,7 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro (pure . Left . PluginInternalError . T.pack . show) $ runExceptT $ cliHandler fileOpts else do + logWith recorder Debug $ LogCompiledInVersion VERSION_fourmolu let format fourmoluConfig = ExceptT $ bimap (PluginInternalError . T.pack . show) (InL . makeDiffTextEdit contents) #if MIN_VERSION_fourmolu(0,11,0) @@ -129,10 +131,13 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro "fourmolu" : v : _ <- pure $ T.words out traverse (readMaybe @Int . T.unpack) $ T.splitOn "." v case version of - Just v -> pure CLIVersionInfo - { noCabal = v >= [0, 7] - } + Just v -> do + logWith recorder Debug $ LogExternalVersion v + pure CLIVersionInfo + { noCabal = v >= [0, 7] + } Nothing -> do + logWith recorder Debug $ LogExternalVersion [] logWith recorder Warning $ NoVersion out pure CLIVersionInfo { noCabal = True @@ -161,6 +166,8 @@ data LogEvent | ConfigPath FilePath | NoConfigPath [FilePath] | StdErr Text + | LogCompiledInVersion String + | LogExternalVersion [Int] deriving (Show) instance Pretty LogEvent where @@ -170,6 +177,11 @@ instance Pretty LogEvent where NoConfigPath ps -> "No " <> pretty configFileName <> " found in any of:" <> line <> indent 2 (vsep (map (pretty . show) ps)) StdErr t -> "Fourmolu stderr:" <> line <> indent 2 (pretty t) + LogCompiledInVersion v -> "Using compiled in fourmolu-" <> pretty v + LogExternalVersion v -> + "Using external fourmolu" + <> if null v then "" else "-" + <> pretty (intercalate "." $ map show v) convertDynFlags :: DynFlags -> [String] convertDynFlags df = diff --git a/plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal b/plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal index 40902789d9..b0e90c21b9 100644 --- a/plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal +++ b/plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal @@ -57,4 +57,5 @@ test-suite tests , hls-ormolu-plugin , hls-test-utils == 2.1.0.0 , lsp-types + , text , ormolu diff --git a/plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs b/plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs index f18323374d..248235dc94 100644 --- a/plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs +++ b/plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs @@ -35,21 +35,23 @@ import System.FilePath (takeFileName) -- --------------------------------------------------------------------- -descriptor :: PluginId -> PluginDescriptor IdeState -descriptor plId = (defaultPluginDescriptor plId) - { pluginHandlers = mkFormattingHandlers provider +descriptor :: Recorder (WithPriority T.Text) -> PluginId -> PluginDescriptor IdeState +descriptor recorder plId = (defaultPluginDescriptor plId) + { pluginHandlers = mkFormattingHandlers $ provider recorder } -- --------------------------------------------------------------------- -provider :: FormattingHandler IdeState -provider ideState typ contents fp _ = ExceptT $ withIndefiniteProgress title Cancellable $ runExceptT $ do +provider :: Recorder (WithPriority T.Text) -> FormattingHandler IdeState +provider recorder ideState typ contents fp _ = ExceptT $ withIndefiniteProgress title Cancellable $ runExceptT $ do ghc <- liftIO $ runAction "Ormolu" ideState $ use GhcSession fp let df = hsc_dflags . hscEnv <$> ghc fileOpts <- case df of Nothing -> pure [] Just df -> pure $ fromDyn df + logWith recorder Debug $ "Using ormolu-" <> VERSION_ormolu + let fullRegion = RegionIndices Nothing Nothing rangeRegion s e = RegionIndices (Just $ s + 1) (Just $ e + 1) diff --git a/plugins/hls-ormolu-plugin/test/Main.hs b/plugins/hls-ormolu-plugin/test/Main.hs index bacb9daa30..8b2e2f77a8 100644 --- a/plugins/hls-ormolu-plugin/test/Main.hs +++ b/plugins/hls-ormolu-plugin/test/Main.hs @@ -4,6 +4,7 @@ module Main ( main ) where +import qualified Data.Text as T import qualified Ide.Plugin.Ormolu as Ormolu import Language.LSP.Protocol.Types import System.FilePath @@ -12,8 +13,8 @@ import Test.Hls main :: IO () main = defaultTestRunner tests -ormoluPlugin :: PluginTestDescriptor () -ormoluPlugin = mkPluginTestDescriptor' Ormolu.descriptor "ormolu" +ormoluPlugin :: PluginTestDescriptor T.Text +ormoluPlugin = mkPluginTestDescriptor Ormolu.descriptor "ormolu" tests :: TestTree tests = testGroup "ormolu" diff --git a/src/HlsPlugins.hs b/src/HlsPlugins.hs index a23051fd9e..e12e5e9f35 100644 --- a/src/HlsPlugins.hs +++ b/src/HlsPlugins.hs @@ -169,7 +169,7 @@ idePlugins recorder = pluginDescToIdePlugins allPlugins let pId = "tactics" in Tactic.descriptor (pluginRecorder pId) pId: #endif #if hls_ormolu - Ormolu.descriptor "ormolu" : + let pId = "ormolu" in Ormolu.descriptor (pluginRecorder pId) pId : #endif #if hls_stylishHaskell StylishHaskell.descriptor "stylish-haskell" :