Skip to content
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

Log fourmolu and ormolu version that hls using #3744

Merged
merged 7 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 15 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,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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -161,6 +166,8 @@ data LogEvent
| ConfigPath FilePath
| NoConfigPath [FilePath]
| StdErr Text
| LogCompiledInVersion String
| LogExternalVersion [Int]
deriving (Show)

instance Pretty LogEvent where
Expand All @@ -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 =
Expand Down
12 changes: 7 additions & 5 deletions plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/HlsPlugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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" :
Expand Down
Loading