Skip to content

Log fourmolu and ormolu version that hls using #3744

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 7 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ 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
import Data.Version (Version, showVersion)
import Development.IDE hiding (pluginHandlers)
import Development.IDE.GHC.Compat as Compat hiding (Cpp, Warning,
hang, vcat)
Expand All @@ -48,6 +50,10 @@ import System.Process.Run (cwd, proc)
import System.Process.Text (readCreateProcessWithExitCode)
import Text.Read (readMaybe)

#if MIN_VERSION_fourmolu(0,12,0)
import qualified Paths_fourmolu as Fourmolu
#endif

descriptor :: Recorder (WithPriority LogEvent) -> PluginId -> PluginDescriptor IdeState
descriptor recorder plId =
(defaultPluginDescriptor plId)
Expand Down Expand Up @@ -75,6 +81,11 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
(pure . Left . PluginInternalError . T.pack . show)
$ runExceptT $ cliHandler fileOpts
else do
#if MIN_VERSION_fourmolu(0,12,0)
logWith recorder Info $ LogBuiltinVersion $ Just Fourmolu.version
#else
logWith recorder Info $ LogBuiltinVersion Nothing
#endif
let format fourmoluConfig = ExceptT $
bimap (PluginInternalError . T.pack . show) (InL . makeDiffTextEdit contents)
#if MIN_VERSION_fourmolu(0,11,0)
Expand Down Expand Up @@ -129,10 +140,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 Info $ LogExternalVersion v
pure CLIVersionInfo
{ noCabal = v >= [0, 7]
}
Nothing -> do
logWith recorder Info $ LogExternalVersion []
logWith recorder Warning $ NoVersion out
pure CLIVersionInfo
{ noCabal = True
Expand Down Expand Up @@ -161,6 +175,8 @@ data LogEvent
| ConfigPath FilePath
| NoConfigPath [FilePath]
| StdErr Text
| LogBuiltinVersion (Maybe Version)
| LogExternalVersion [Int]
deriving (Show)

instance Pretty LogEvent where
Expand All @@ -170,6 +186,8 @@ 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)
LogBuiltinVersion v -> "Using builtin fourmolu" <> pretty (maybe "" showVersion v)
LogExternalVersion v -> "Using external fourmolu" <> pretty (intercalate "." $ map show v)

convertDynFlags :: DynFlags -> [String]
convertDynFlags df =
Expand Down