summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-08-10 17:14:47 +0900
committerJasper Van der Jeugt <m@jaspervdj.be>2012-08-10 17:14:47 +0900
commit0acf5931a702dfcd7934b861e4ff1f64c96137dd (patch)
treea4b4b8b9ae50fcfd8722f0a456d1b207086ddb0a /src
parentd61a5e0a7e90c130a3b1d5af40c5bc02f4b61f61 (diff)
downloadstylish-haskell-0acf5931a702dfcd7934b861e4ff1f64c96137dd.tar.gz
A bit more drafting
Diffstat (limited to 'src')
-rw-r--r--src/StylishHaskell/Step/Records.hs36
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)