diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-08-10 17:14:47 +0900 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-08-10 17:14:47 +0900 |
commit | 0acf5931a702dfcd7934b861e4ff1f64c96137dd (patch) | |
tree | a4b4b8b9ae50fcfd8722f0a456d1b207086ddb0a | |
parent | d61a5e0a7e90c130a3b1d5af40c5bc02f4b61f61 (diff) | |
download | stylish-haskell-0acf5931a702dfcd7934b861e4ff1f64c96137dd.tar.gz |
A bit more drafting
-rw-r--r-- | src/StylishHaskell/Step/Records.hs | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/StylishHaskell/Step/Records.hs b/src/StylishHaskell/Step/Records.hs index 6b25ee4..a754428 100644 --- a/src/StylishHaskell/Step/Records.hs +++ b/src/StylishHaskell/Step/Records.hs @@ -3,11 +3,13 @@ module StylishHaskell.Step.Records where -------------------------------------------------------------------------------- +import Data.List (nub) import qualified Language.Haskell.Exts.Annotated as H -------------------------------------------------------------------------------- import StylishHaskell.Block +import StylishHaskell.Editor -------------------------------------------------------------------------------- @@ -21,10 +23,32 @@ records modu = -------------------------------------------------------------------------------- -fieldLines :: [H.FieldDecl H.SrcSpanInfo] -> Maybe [Int] -fieldLines rec - | all singleLine blocks = Just $ map blockStart blocks - | otherwise = Nothing +-- | Align the types of a field +{- +alignType :: Int -> H.FieldDecl H.SrcSpan -> Int -> Change String +alignType longest (H.FieldDecl _ names _) line = where - blocks = map (linesFromSrcSpan . H.ann) rec - singleLine b = blockStart b == blockEnd b + end = +-} + + +-------------------------------------------------------------------------------- +-- | Find the length of the longest field name in a record +longestFieldName :: [H.FieldDecl H.SrcSpan] -> Int +longestFieldName fields = maximum + [ H.srcSpanEndColumn $ H.ann name + | H.FieldDecl _ names _ <- fields + , name <- names + ] + + +-------------------------------------------------------------------------------- +-- | Checks that all no field of the record appears on more than one line, +-- amonst other things +fixable :: [H.FieldDecl H.SrcSpan] -> Bool +fixable [] = False +fixable fields = all singleLine srcSpans && nonOverlapping srcSpans + where + srcSpans = map H.ann fields + singleLine s = H.srcSpanStartLine s == H.srcSpanEndLine s + nonOverlapping ss = length ss == length (nub $ map H.srcSpanStartLine ss) |