-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Add fourmolu plugin #161
Closed
Closed
Add fourmolu plugin #161
Changes from all 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 1e743a0
Ormolu already handles file pragmas
pepeiborra 158a279
Progress reporting
pepeiborra cee4232
Add fourmolu plugin
georgefst 4c76137
Add test for fourmolu
georgefst 825789c
Add fourmolu to stack extra-deps
georgefst 72df5ff
Update Fourmolu to 0.1
georgefst 1ccbf34
Load Fourmolu config files
georgefst 114aa8a
Fix for CPP
georgefst 605d19a
Fix haddock parse error in install.hs
georgefst 4fe0f7d
Merge pull request #255 from georgefst/patch-1
fendor 3a6874d
Add more tests for checking formatting
sureyeaah 96d42f3
Add more tests for ormolu
sureyeaah d4371fd
Fix bug in diffOperationToTextEdit
sureyeaah 75f0d6b
Fix another bug in diffOperationToTextEdit
sureyeaah 679e0ec
Don't normalize in ormolu
sureyeaah f51d4e8
Ormolu RegionIndices should be 1-based
sureyeaah 7a8f51d
Remove *.ormolu.unchanged formatting tests
sureyeaah 5dbf153
Remove redundant CircleCI steps
lukel97 530ccb0
Merge pull request #246 from pepeiborra/ormolu
fendor 5163c41
Merge pull request #257 from sureyeaah/ormolu-fix
lukel97 6b51c7c
Remove hspec-expectations
lukel97 3dbfa68
Merge pull request #259 from haskell/remove-redundant-circleci-steps
lukel97 38672e0
Slow down Tasty by limiting it to -j1
lukel97 bd5e256
Merge pull request #261 from haskell/fix-ci
lukel97 26f1e7f
Remove a redundant caching step
Ailrun 0adf4bd
Merge pull request #260 from bubba/remove-hspec-expectations
lukel97 75d4c62
Merge pull request #262 from Ailrun/fix-ci
lukel97 a308151
Fix compression extension on GitHub build artifacts
lukel97 d961197
Add fourmolu plugin
georgefst e0ea2fe
Merge branch 'master' into fourmolu
georgefst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE PackageImports #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Ide.Plugin.Fourmolu | ||
( | ||
descriptor | ||
, provider | ||
) | ||
where | ||
|
||
import Control.Exception | ||
import qualified Data.Text as T | ||
import Development.IDE.Core.Rules | ||
import Development.IDE.Core.RuleTypes (GhcSession (GhcSession)) | ||
import Development.IDE.Core.Shake (use) | ||
import Development.IDE.GHC.Util (hscEnv) | ||
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 GHC.LanguageExtensions.Type | ||
import GhcPlugins (HscEnv (hsc_dflags)) | ||
import Ide.Plugin.Formatter | ||
import Ide.PluginUtils | ||
import Ide.Types | ||
import Language.Haskell.LSP.Core (LspFuncs (withIndefiniteProgress), | ||
ProgressCancellable (Cancellable)) | ||
import Language.Haskell.LSP.Types | ||
import "fourmolu" Ormolu | ||
import System.FilePath (takeFileName) | ||
import Text.Regex.TDFA.Text () | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
descriptor :: PluginId -> PluginDescriptor | ||
descriptor plId = (defaultPluginDescriptor plId) | ||
{ pluginFormattingProvider = Just provider | ||
} | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
provider :: FormattingProvider IO | ||
provider lf ideState typ contents fp _ = withIndefiniteProgress lf title Cancellable $ do | ||
let | ||
fromDyn :: DynFlags -> IO [DynOption] | ||
fromDyn df = | ||
let | ||
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 showExtension $ S.toList $ D.extensionFlags df | ||
in | ||
return $ map DynOption $ pp <> pm <> ex | ||
|
||
ghc <- runAction "Fourmolu" ideState $ use GhcSession fp | ||
let df = hsc_dflags . hscEnv <$> ghc | ||
fileOpts <- case df of | ||
Nothing -> return [] | ||
Just df -> fromDyn df | ||
|
||
let | ||
fullRegion = RegionIndices Nothing Nothing | ||
rangeRegion s e = RegionIndices (Just $ s + 1) (Just $ e + 1) | ||
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 (Range (Position sl _) (Position el _)) -> | ||
ret <$> (fmt contents =<< mkConf fileOpts (rangeRegion sl el)) | ||
where | ||
title = T.pack $ "Formatting " <> takeFileName (fromNormalizedFilePath fp) | ||
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) | ||
|
||
showExtension :: Extension -> String | ||
showExtension Cpp = "-XCPP" | ||
showExtension other = "-X" ++ show other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.