-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify Signature to look top level func signatures and prepare for fo…
…rmatting
- Loading branch information
1 parent
2b80feb
commit ba1f7d1
Showing
2 changed files
with
40 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
{-# LANGUAGE BlockArguments #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
module Language.Haskell.Stylish.Step.Signature where | ||
|
||
import RdrName (RdrName) | ||
import SrcLoc (GenLocated (..), Located) | ||
import GHC.Hs.Decls (HsDecl(..)) | ||
import GHC.Hs.Binds (Sig(..)) | ||
import GHC.Hs.Extension (GhcPs) | ||
|
||
-------------------------------------------------------------------------------- | ||
import Language.Haskell.Stylish.Block | ||
import Language.Haskell.Stylish.Step | ||
import Language.Haskell.Stylish.Module | ||
import Language.Haskell.Stylish.Editor (change) | ||
import Language.Haskell.Stylish.GHC (getStartLineUnsafe, getEndLineUnsafe) | ||
import Language.Haskell.Stylish.Editor (Change, applyChanges) | ||
|
||
-- TODO unify with type alias from Data.hs | ||
type ChangeLine = Change String | ||
|
||
data Config = Config | ||
{ maxColumnLength :: Int | ||
{ cMaxColumns :: Int | ||
} | ||
|
||
step :: Config -> Step | ||
step _ = makeStep "Signature" (\ls _ -> ls) | ||
step cfg = makeStep "Signature" (\ls m -> applyChanges (changes cfg m) ls) | ||
|
||
changes :: Config -> Module -> [ChangeLine] | ||
changes cfg m = fmap (formatSignatureDecl cfg m) (topLevelFunctionSignatures m) | ||
|
||
topLevelFunctionSignatures :: Module -> [Located SignatureDecl] | ||
topLevelFunctionSignatures = queryModule @(Located (HsDecl GhcPs)) \case | ||
L pos (SigD _ (TypeSig _ [name] _)) -> [L pos $ MkSignatureDecl name] | ||
_ -> [] | ||
|
||
data SignatureDecl = MkSignatureDecl | ||
{ sigName :: Located RdrName | ||
} | ||
|
||
formatSignatureDecl :: Config -> Module -> Located SignatureDecl -> ChangeLine | ||
formatSignatureDecl _cfg _m ldecl = change originalDeclBlock id | ||
where | ||
originalDeclBlock = | ||
Block (getStartLineUnsafe ldecl) (getEndLineUnsafe ldecl) |
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