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

Load default operator fixities in Fourmolu plugin non-CLI mode #3855

Merged
merged 8 commits into from
Oct 31, 2023
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
28 changes: 14 additions & 14 deletions plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

module Ide.Plugin.Fourmolu (
descriptor,
provider,
LogEvent,
) where

import Control.Exception (IOException, handle, try)
import Control.Exception
import Control.Lens ((^.))
import Control.Monad (guard)
import Control.Monad.Error.Class (MonadError (throwError))
import Control.Monad.Trans.Except (ExceptT (..), mapExceptT,
runExceptT)

import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.Trans.Class (MonadTrans (lift))
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
import Data.Bifunctor (bimap)
import Data.List (intercalate)
import Data.Maybe (catMaybes)
Expand Down Expand Up @@ -96,6 +93,9 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err)

let config =
#if MIN_VERSION_fourmolu(0,13,0)
refineConfig ModuleSource Nothing Nothing Nothing
#endif
defaultConfig
{ cfgDynOptions = map DynOption fileOpts
, cfgFixityOverrides = cfgFileFixities
Expand Down
5 changes: 4 additions & 1 deletion plugins/hls-fourmolu-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Main
) where

import Data.Aeson
import qualified Data.Aeson.KeyMap as KM
import Data.Functor
import Ide.Plugin.Config
import qualified Ide.Plugin.Fourmolu as Fourmolu
Expand All @@ -28,12 +29,14 @@ tests =
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
, goldenWithFourmolu cli "formats imports correctly" "Fourmolu2" "formatted" $ \doc -> do
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
, goldenWithFourmolu cli "uses correct operator fixities" "Fourmolu3" "formatted" $ \doc -> do
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
]

goldenWithFourmolu :: Bool -> TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
goldenWithFourmolu cli title path desc = goldenWithHaskellDocFormatter def fourmoluPlugin "fourmolu" conf title testDataDir path desc "hs"
where
conf = def{plcConfig = (\(Object obj) -> obj) $ object ["external" .= cli]}
conf = def{plcConfig = KM.fromList ["external" .= cli]}

testDataDir :: FilePath
testDataDir = "test" </> "testdata"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
b :: Bool
b =
id $
id $
case True && True of
True -> True
False -> False
6 changes: 6 additions & 0 deletions plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
b :: Bool
b =
id $ id $
case True && True of
True -> True
False -> False
Loading