mirror of
https://github.com/ilyakooo0/ormolu.git
synced 2024-09-11 16:36:31 +03:00
Preserve blank lines in ‘let’ and ‘where’ bindings
This commit is contained in:
parent
033bb16032
commit
a877785709
@ -19,6 +19,9 @@
|
||||
* Fixed rendering of function arguments in multiline layout. [Issue
|
||||
609](https://github.com/tweag/ormolu/issues/609).
|
||||
|
||||
* Blank lines between definitions in `let` and `while` bindings are now
|
||||
preserved. [Issue 554](https://github.com/tweag/ormolu/issues/554).
|
||||
|
||||
## Ormolu 0.1.0.0
|
||||
|
||||
* Fixed rendering of type signatures concerning several identifiers. [Issue
|
||||
|
@ -0,0 +1,6 @@
|
||||
foo =
|
||||
let x = 10
|
||||
|
||||
y = 11
|
||||
z = 12
|
||||
in x + y + z
|
@ -0,0 +1,9 @@
|
||||
foo =
|
||||
let
|
||||
|
||||
x = 10
|
||||
|
||||
y = 11
|
||||
z = 12
|
||||
|
||||
in x + y + z
|
@ -0,0 +1,6 @@
|
||||
foo = x + y + z
|
||||
where
|
||||
x = 10
|
||||
|
||||
y = 11
|
||||
z = 12
|
@ -0,0 +1,7 @@
|
||||
foo = x + y + z
|
||||
where
|
||||
|
||||
x = 10
|
||||
|
||||
y = 11
|
||||
z = 12
|
@ -5,7 +5,7 @@ Formatting is not idempotent:
|
||||
Please, consider reporting the bug.
|
||||
|
||||
Formatting is not idempotent:
|
||||
src/full/Agda/Syntax/Translation/InternalToAbstract.hs<rendered>:750:4
|
||||
src/full/Agda/Syntax/Translation/InternalToAbstract.hs<rendered>:769:4
|
||||
before: " nes\n\n "
|
||||
after: " nes\n\n -- Andreas"
|
||||
Please, consider reporting the bug.
|
||||
|
@ -1,5 +1,5 @@
|
||||
Formatting is not idempotent:
|
||||
src/InteractiveUI.hs<rendered>:3710:33
|
||||
src/InteractiveUI.hs<rendered>:3757:33
|
||||
before: "text \"Try\" <+> doWha"
|
||||
after: "text \"Try\"\n "
|
||||
Please, consider reporting the bug.
|
||||
|
@ -1,5 +1,5 @@
|
||||
Formatting is not idempotent:
|
||||
src/IDE/Pane/Modules.hs<rendered>:1187:7
|
||||
src/IDE/Pane/Modules.hs<rendered>:1189:7
|
||||
before: "cr\n -- show"
|
||||
after: "cr\n in -- show"
|
||||
Please, consider reporting the bug.
|
||||
|
@ -353,7 +353,14 @@ p_hsCmdTop = \case
|
||||
HsCmdTop NoExtField cmd -> located cmd p_hsCmd
|
||||
XCmdTop x -> noExtCon x
|
||||
|
||||
withSpacing :: Data a => (a -> R ()) -> Located a -> R ()
|
||||
-- | Render an expression preserving blank lines between such consecutive
|
||||
-- expressions found in the original source code.
|
||||
withSpacing ::
|
||||
-- | Rendering function
|
||||
(a -> R ()) ->
|
||||
-- | Entity to render
|
||||
Located a ->
|
||||
R ()
|
||||
withSpacing f l = located l $ \x -> do
|
||||
case getLoc l of
|
||||
UnhelpfulSpan _ -> f x
|
||||
@ -464,30 +471,24 @@ gatherStmtBlock (XParStmtBlock x) = noExtCon x
|
||||
p_hsLocalBinds :: HsLocalBindsLR GhcPs GhcPs -> R ()
|
||||
p_hsLocalBinds = \case
|
||||
HsValBinds NoExtField (ValBinds NoExtField bag lsigs) -> do
|
||||
let ssStart =
|
||||
either
|
||||
(srcSpanStart . getLoc)
|
||||
(srcSpanStart . getLoc)
|
||||
items =
|
||||
(Left <$> bagToList bag) ++ (Right <$> lsigs)
|
||||
p_item (Left x) = located x p_valDecl
|
||||
p_item (Right x) = located x p_sigDecl
|
||||
-- When in a single-line layout, there is a chance that the inner
|
||||
-- elements will also contain semicolons and they will confuse the
|
||||
-- parser. so we request braces around every element except the last.
|
||||
br <- layoutToBraces <$> getLayout
|
||||
sitcc $
|
||||
sepSemi
|
||||
( \(p, i) ->
|
||||
( case p of
|
||||
SinglePos -> id
|
||||
FirstPos -> br
|
||||
MiddlePos -> br
|
||||
LastPos -> id
|
||||
)
|
||||
(p_item i)
|
||||
)
|
||||
(attachRelativePos $ sortOn ssStart items)
|
||||
let items =
|
||||
let injectLeft (L l x) = L l (Left x)
|
||||
injectRight (L l x) = L l (Right x)
|
||||
in (injectLeft <$> bagToList bag) ++ (injectRight <$> lsigs)
|
||||
positionToBracing = \case
|
||||
SinglePos -> id
|
||||
FirstPos -> br
|
||||
MiddlePos -> br
|
||||
LastPos -> id
|
||||
p_item' (p, item) =
|
||||
positionToBracing p $
|
||||
withSpacing (either p_valDecl p_sigDecl) item
|
||||
binds = sortOn (srcSpanStart . getLoc) items
|
||||
sitcc $ sepSemi p_item' (attachRelativePos binds)
|
||||
HsValBinds NoExtField _ -> notImplemented "HsValBinds"
|
||||
HsIPBinds NoExtField (IPBinds NoExtField xs) ->
|
||||
-- Second argument of IPBind is always Left before type-checking.
|
||||
|
Loading…
Reference in New Issue
Block a user