1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE RecordWildCards #-}
4-- | Rendering of modules.
6module Ormolu.Printer.Meat.Module
12import Data.Maybe (isJust)
15import Ormolu.Printer.Combinators
16import Ormolu.Printer.Comments
17import Ormolu.Printer.Meat.Common
18import Ormolu.Printer.Meat.Declaration
19import Ormolu.Printer.Meat.ImportExport
21import SrcLoc (combineSrcSpans)
23p_hsModule :: ParsedSource -> R ()
24p_hsModule loc@(L moduleSpan hsModule) = do
25 -- NOTE If span of exports in multiline, the whole thing is multiline.
26 -- This is especially important because span of module itself always seems
27 -- to have length zero, so it's not reliable for layout selection.
29 case hsmodExports hsModule of
31 Just (L exportsSpan _) -> combineSrcSpans moduleSpan exportsSpan
32 locatedVia (Just spn) loc $ \HsModule {..} -> do
35 Just hsmodName' -> line $ do
36 located hsmodName' p_hsmodName
39 Just hsmodExports' -> do
41 inci (locatedVia Nothing hsmodExports' p_hsmodExports)
44 when (not (null hsmodImports) || not (null hsmodDecls)) newline
45 forM_ (sortImports hsmodImports) (located' p_hsmodImport)
46 when (not (null hsmodImports) && not (null hsmodDecls)) newline
48 forM_ (zip hsmodDecls ((Just <$> drop 1 hsmodDecls) ++ [Nothing])) $
51 Nothing -> located d p_hsDecl
53 if separatedDecls (unL d) (unL d')
54 then line (located d p_hsDecl)
55 else located d p_hsDecl
57 trailingComments <- hasMoreComments
58 when (trailingComments && isJust hsmodName) newline
61-- | Determine if these declarations should be separated by a blank line.
67separatedDecls (SigD NoExt (TypeSig NoExt (n:_) _)) (ValD NoExt (FunBind NoExt n' _ _ _)) =
69separatedDecls _ _ = True
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list