Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6680505
Fix rendering of extension flags for Ormolu
pepeiborra Jul 27, 2020
1e743a0
Ormolu already handles file pragmas
pepeiborra Jul 27, 2020
158a279
Progress reporting
pepeiborra Jul 27, 2020
cee4232
Add fourmolu plugin
georgefst Jun 14, 2020
4c76137
Add test for fourmolu
georgefst Jun 14, 2020
825789c
Add fourmolu to stack extra-deps
georgefst Jun 18, 2020
72df5ff
Update Fourmolu to 0.1
georgefst Jul 2, 2020
1ccbf34
Load Fourmolu config files
georgefst Jul 2, 2020
114aa8a
Fix for CPP
georgefst Jul 2, 2020
605d19a
Fix haddock parse error in install.hs
georgefst Jul 29, 2020
4fe0f7d
Merge pull request #255 from georgefst/patch-1
fendor Jul 29, 2020
3a6874d
Add more tests for checking formatting
sureyeaah Jul 30, 2020
96d42f3
Add more tests for ormolu
sureyeaah Jul 30, 2020
d4371fd
Fix bug in diffOperationToTextEdit
sureyeaah Jul 30, 2020
75f0d6b
Fix another bug in diffOperationToTextEdit
sureyeaah Jul 30, 2020
679e0ec
Don't normalize in ormolu
sureyeaah Jul 30, 2020
f51d4e8
Ormolu RegionIndices should be 1-based
sureyeaah Jul 30, 2020
7a8f51d
Remove *.ormolu.unchanged formatting tests
sureyeaah Jul 30, 2020
5dbf153
Remove redundant CircleCI steps
lukel97 Jul 31, 2020
530ccb0
Merge pull request #246 from pepeiborra/ormolu
fendor Jul 31, 2020
5163c41
Merge pull request #257 from sureyeaah/ormolu-fix
lukel97 Jul 31, 2020
6b51c7c
Remove hspec-expectations
lukel97 Jul 31, 2020
3dbfa68
Merge pull request #259 from haskell/remove-redundant-circleci-steps
lukel97 Jul 31, 2020
38672e0
Slow down Tasty by limiting it to -j1
lukel97 Jul 31, 2020
bd5e256
Merge pull request #261 from haskell/fix-ci
lukel97 Jul 31, 2020
26f1e7f
Remove a redundant caching step
Ailrun Jul 31, 2020
0adf4bd
Merge pull request #260 from bubba/remove-hspec-expectations
lukel97 Jul 31, 2020
75d4c62
Merge pull request #262 from Ailrun/fix-ci
lukel97 Jul 31, 2020
a308151
Fix compression extension on GitHub build artifacts
lukel97 Jul 31, 2020
d961197
Add fourmolu plugin
georgefst Aug 1, 2020
e0ea2fe
Merge branch 'master' into fourmolu
georgefst Aug 1, 2020
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
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ package ghcide
write-ghc-environment-files: never

index-state: 2020-07-27T12:40:45Z

allow-newer:
floskell:aeson
HsYAML-aeson:aeson
stylish-haskell:aeson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to remove these before merging.

I've got an eye on the relevant PRs - thanks @bubba for opening them where necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the remaining packages blocked by aeson-1.5?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Floskell got the bump, but there hasn't been a Hackage release with it.

We're still waiting on Stylish.

2 changes: 2 additions & 0 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import Ide.Plugin.Example2 as Example2
import Ide.Plugin.GhcIde as GhcIde
import Ide.Plugin.Floskell as Floskell
import Ide.Plugin.Ormolu as Ormolu
import Ide.Plugin.Fourmolu as Fourmolu
import Ide.Plugin.StylishHaskell as StylishHaskell
#if AGPL
import Ide.Plugin.Brittany as Brittany
Expand Down Expand Up @@ -103,6 +104,7 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
, Floskell.descriptor "floskell"
-- , genericDescriptor "generic"
-- , ghcmodDescriptor "ghcmod"
, Fourmolu.descriptor "fourmolu"
, Ormolu.descriptor "ormolu"
, StylishHaskell.descriptor "stylish-haskell"
#if AGPL
Expand Down
2 changes: 1 addition & 1 deletion ghcide
2 changes: 2 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ library
Ide.Plugin.Eval
Ide.Plugin.Example
Ide.Plugin.Example2
Ide.Plugin.Fourmolu
Ide.Plugin.GhcIde
Ide.Plugin.Ormolu
Ide.Plugin.Pragmas
Expand All @@ -70,6 +71,7 @@ library
, extra
, filepath
, floskell == 0.10.*
, fourmolu ^>= 0.1.0.0
, ghc
, ghcide >= 0.1
, gitrev
Expand Down
89 changes: 89 additions & 0 deletions src/Ide/Plugin/Fourmolu.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}

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

import Control.Exception
import qualified Data.Text as T
import Development.IDE.Core.Rules
import Development.IDE.Types.Diagnostics as D
import Development.IDE.Types.Location
import qualified DynFlags as D
import qualified EnumSet as S
import GHC
import Ide.Types
import Ide.PluginUtils
import Ide.Plugin.Formatter
import Language.Haskell.LSP.Types
import "fourmolu" Ormolu
import Text.Regex.TDFA.Text()

-- ---------------------------------------------------------------------

descriptor :: PluginId -> PluginDescriptor
descriptor plId = (defaultPluginDescriptor plId)
{ pluginFormattingProvider = Just provider
}

-- ---------------------------------------------------------------------

provider :: FormattingProvider IO
provider _lf ideState typ contents fp _ = do
let
fromDyn :: ParsedModule -> IO [DynOption]
fromDyn pmod =
let
df = ms_hspp_opts $ pm_mod_summary pmod
pp =
let p = D.sPgm_F $ D.settings df
in if null p then [] else ["-pgmF=" <> p]
pm = map (("-fplugin=" <>) . moduleNameString) $ D.pluginModNames df
ex = map (("-X" <>) . show') $ S.toList $ D.extensionFlags df
show' x = case show x of
"Cpp" -> "CPP"
s -> s
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll do for now. Really, we shouldn't have to rely on show here anyway...

It actually looks like it wouldn't take much of a refactoring to allow passing the DynFlags directly. I'll see if I can get this fixed upstream in Ormolu.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually looks like it wouldn't take much of a refactoring to allow passing the DynFlags directly.

Turns out to be slightly tricky because of the ghc/ghc-lib type mismatch. I'll be curious to see how @jneira solves this issue for HLint.

in
return $ map DynOption $ pp <> pm <> ex

m_parsed <- runAction "Fourmolu" ideState $ getParsedModule fp
fileOpts <- case m_parsed of
Nothing -> return []
Just pm -> fromDyn pm

let
fullRegion = RegionIndices Nothing Nothing
rangeRegion s e = RegionIndices (Just s) (Just e)
mkConf o region = do
printerOpts <- loadConfigFile True (Just fp') defaultPrinterOpts
return $ defaultConfig
{ cfgDynOptions = o
, cfgRegion = region
, cfgDebug = True
, cfgPrinterOpts = printerOpts
}
fmt :: T.Text -> Config RegionIndices -> IO (Either OrmoluException T.Text)
fmt cont conf =
try @OrmoluException (ormolu conf fp' $ T.unpack cont)
fp' = fromNormalizedFilePath fp

case typ of
FormatText -> ret <$> (fmt contents =<< mkConf fileOpts fullRegion)
FormatRange r ->
let
Range (Position sl _) (Position el _) = normalize r
in
ret <$> (fmt contents =<< mkConf fileOpts (rangeRegion sl el))
where
ret :: Either OrmoluException T.Text -> Either ResponseError (List TextEdit)
ret (Left err) = Left
(responseError (T.pack $ "fourmoluCmd: " ++ show err) )
ret (Right new) = Right (makeDiffTextEdit contents new)
3 changes: 2 additions & 1 deletion src/Ide/Plugin/Ormolu.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -23,7 +24,7 @@ import Ide.Types
import Ide.PluginUtils
import Ide.Plugin.Formatter
import Language.Haskell.LSP.Types
import Ormolu
import "ormolu" Ormolu
import Text.Regex.TDFA.Text()

-- ---------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions stack-8.10.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extra-deps:
- cabal-plan-0.7.0.0
- clock-0.7.2
- floskell-0.10.3
- fourmolu-0.1.0.0
- ghc-exactprint-0.6.3
- lens-4.19.1
- lsp-test-0.11.0.3
Expand Down
1 change: 1 addition & 0 deletions stack-8.6.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extra-deps:
# - ghcide-0.1.0
- extra-1.7.3
- floskell-0.10.3
- fourmolu-0.1.0.0
- fuzzy-0.1.0.0
- ghc-check-0.5.0.1
- ghc-exactprint-0.6.2 # for HaRe
Expand Down
1 change: 1 addition & 0 deletions stack-8.6.5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extra-deps:
- clock-0.7.2
- extra-1.7.3
- floskell-0.10.3
- fourmolu-0.1.0.0
- fuzzy-0.1.0.0
# - ghcide-0.1.0
- ghc-check-0.5.0.1
Expand Down
1 change: 1 addition & 0 deletions stack-8.8.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extra-deps:
- constrained-dynamic-0.1.0.0
- extra-1.7.3
- floskell-0.10.3
- fourmolu-0.1.0.0
# - ghcide-0.1.0
- ghc-check-0.5.0.1
- ghc-lib-parser-8.10.1.20200523
Expand Down
1 change: 1 addition & 0 deletions stack-8.8.3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extra-deps:
- constrained-dynamic-0.1.0.0
- extra-1.7.3
- floskell-0.10.3
- fourmolu-0.1.0.0
# - ghcide-0.1.0
- haskell-src-exts-1.21.1
- hie-bios-0.6.1
Expand Down
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extra-deps:
- clock-0.7.2
- extra-1.7.3
- floskell-0.10.3
- fourmolu-0.1.0.0
- fuzzy-0.1.0.0
# - ghcide-0.1.0
- ghc-check-0.5.0.1
Expand Down
12 changes: 12 additions & 0 deletions test/functional/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tests = testGroup "format document" [
, brittanyTests
#endif
, ormoluTests
, fourmoluTests
]

rangeTests :: TestTree
Expand Down Expand Up @@ -156,6 +157,17 @@ ormoluTests = testGroup "ormolu" [
GHC86 -> "formatted"
_ -> "unchanged"

fourmoluTests :: TestTree
fourmoluTests = testGroup "fourmolu" [
goldenVsStringDiff "formats correctly" goldenGitDiff ("test/testdata/Format.fourmolu.hs") $ runSession hieCommand fullCaps "test/testdata" $ do
let formatLspConfig provider =
object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already defined on lines 172-173

Suggested change
let formatLspConfig provider =
object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]

sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "fourmolu"))
doc <- openDoc "Format.hs" "haskell"
formatDoc doc (FormattingOptions 4 True)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
]


formatLspConfig :: Value -> Value
formatLspConfig provider = object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ]
Expand Down
12 changes: 12 additions & 0 deletions test/testdata/Format.fourmolu.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Format where

foo :: Int -> Int
foo 3 = 2
foo x = x
bar :: String -> IO String
bar s = do
x <- return "hello"
return "asdf"

data Baz = Baz {a :: Int, b :: String}